Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More compatibility updates for SILE 0.15 #13

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions silex/classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class.type = "class"
class._name = "base"

class._initialized = false
class.deferredLegacyInit = {}
class.deferredInit = {}
class.pageTemplate = { frames = {}, firstContentFrame = nil }
class.defaultFrameset = {}
Expand Down Expand Up @@ -73,6 +72,7 @@ function class:_init (options)
end

function class:_post_init ()
SILE.documentState.documentClass = self
self._initialized = true
for i, func in ipairs(self.deferredInit) do
func(self)
Expand Down Expand Up @@ -222,13 +222,22 @@ function class:initPackage (pack, options)
end
end

function class:registerLegacyPostinit (func, options)
if self._initialized then return func(self, options) end
table.insert(self.deferredLegacyInit, function (_)
func(self, options)
end)
end

--- Register a callback function to be executed after the class initialization has completed.
-- Sometimes a class or package may want to run things after the class has been fully initialized. This can be useful
-- for setting document settings after packages and all their dependencies have been loaded. For example a package might
-- want to trigger something to happen after all frames have been defined, but the package itself doesn't know if it is
-- being loaded before or after the document options are processed, frame masters have been setup, etc. Rather than
-- relying on the user to load the package after these events, the package can use this callback to deffer the action
-- until those things can be reasonable expected to have completed.
--
-- Functions in the deferred initialization queue are run on a first-set first-run basis.
--
-- Note the typesetter will *not* have been instantiated yet, so is not appropriate to try to output content at this
-- point. Injecting content to be processed at the start of a document should be done with preambles. The inputter
-- *will* be instantiated at this point, so adding a new preamble is viable.
-- If the class has already been initialized the callback function will be run immediately.
-- @tparam function func Callback function accepting up to two arguments.
-- @tparam[opt] table options Additional table passed as a second argument to the callback.
function class:registerPostinit (func, options)
if self._initialized then return func(self, options) end
table.insert(self.deferredInit, function (_)
Expand Down
6 changes: 3 additions & 3 deletions silex/lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SILE.X.forLanguage = forLanguage

-- Now we can patch the language support module, hacking the initial implementation
local icu = require("justenoughicu")
local loadonce = {}
SILE.scratch.loaded_languages = {}
SILE.languageSupport.languages = {}
-- BEGIN OMIKHLEIA HACKLANG
-- BAD CODE SMELL WARNING
Expand Down Expand Up @@ -60,8 +60,8 @@ SILE.languageSupport.loadLanguage = function (language)
end
-- END OMIKHLEIA HACKLANG

if loadonce[language] then return end
loadonce[language] = true
if SILE.scratch.loaded_languages[language] then return end
SILE.scratch.loaded_languages[language] = true

-- BEGIN OMIKHLEIA HACKLANG
-- We need to find language resources for this BCP47 identifier, from the less specific
Expand Down