Skip to content

Commit

Permalink
[NFY] refactor(classes)!: Convert class inheritance from stdlib to Pe…
Browse files Browse the repository at this point in the history
…nlight

BREAKING CHANGE:
  • Loading branch information
alerque committed Sep 23, 2020
1 parent 60e9fbf commit 9f23a1d
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 265 deletions.
116 changes: 81 additions & 35 deletions classes/base.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return std.object {
registerCommands = (function ()
local _oldbase = {
registerCommands = function ()

SILE.registerCommand("script", function (options, content)
if (options["src"]) then
Expand Down Expand Up @@ -84,7 +84,7 @@ return std.object {
SILE.typesetter:endline()
end, "Ends the current paragraph.")

end),
end,

pageTemplate = std.object { frames = {}, firstContentFrame = nil },

Expand All @@ -100,25 +100,6 @@ return std.object {
end
end,

init = function (self)
SILE.settings.declare({
parameter = "current.parindent",
type = "glue or nil",
default = nil,
help = "Glue at start of paragraph"
})
SILE.outputter:init(self)
self:registerCommands()
-- Call all stored package init routines
for i = 1, #(SILE.classes.base.deferredInit) do (SILE.classes.base.deferredInit[i])() end
SILE.typesetter:registerPageEndHook(function ()
if SU.debugging("frames") then
for _, v in pairs(SILE.frames) do SILE.outputter:debugFrame(v) end
end
end)
return self:initialFrame()
end,

initialFrame = function (self)
SILE.documentState.thisPageTemplate = pl.tablex.deepcopy(self.pageTemplate)
SILE.frames = { page = SILE.frames.page }
Expand Down Expand Up @@ -190,18 +171,83 @@ return std.object {
endPar = function (typesetter)
typesetter:pushVglue(SILE.settings.get("document.parskip"))
end,
}

options = {
papersize = function (size)
SILE.documentState.paperSize = SILE.papersize(size)
SILE.documentState.orgPaperSize = SILE.documentState.paperSize
SILE.newFrame({
id = "page",
left = 0,
top = 0,
right = SILE.documentState.paperSize[1],
bottom = SILE.documentState.paperSize[2]
local base = pl.class({
type = "class",
deferredInit = {},
pageTemplate = _oldbase.pageTemplate,
defaultFrameset = {},
firstContentFrame = "page",
options = {},

_init = function (self, options)
if not options then options = {} end
self:declareOption("class", function (name) return name end)
self:declareOption("papersize", function (size)
SILE.documentState.paperSize = SILE.papersize(size)
SILE.documentState.orgPaperSize = SILE.documentState.paperSize
SILE.newFrame({
id = "page",
left = 0,
top = 0,
right = SILE.documentState.paperSize[1],
bottom = SILE.documentState.paperSize[2]
})
return size
end)
SU.debug("foo", type(options))
for k, v in pairs(options) do
self.options[k] = v
end
SILE.outputter:init(self)
self:declareSettings()
self:registerCommands()
self:declareFrames(self.defaultFrameset)
-- self.pageTemplate.firstContentFrame = self.pageTemplate.frames[self.firstContentFrame]
for i = 1, #(SILE.classes.base.deferredInit) do (SILE.classes.base.deferredInit[i])() end
SILE.typesetter:registerPageEndHook(function ()
if SU.debugging("frames") then
for _, v in pairs(SILE.frames) do SILE.outputter:debugFrame(v) end
end
end)
-- return self:initialFrame()
end,

declareOption = function (self, option, setter)
if not getmetatable(self.options) then
setmetatable(self.options, {
__newindex = function (self, key, value)
local setter = getmetatable(self)[key]
if not setter then
SU.error("Attempted to set a class option '" .. key .. "' that isn’t registered.")
end
rawset(self, key, setter(value))
end
})
end
getmetatable(self.options)[option] = setter
end,

declareSettings = function (_)
SILE.settings.declare({
parameter = "current.parindent",
type = "glue or nil",
default = nil,
help = "Glue at start of paragraph"
})
end
}
}
end,

loadPackage = _oldbase.loadPackage,
registerCommands = _oldbase.registerCommands,
initialFrame = _oldbase.initialFrame,
declareFrame = _oldbase.declareFrame,
declareFrames = _oldbase.declareFrames,
newPar = _oldbase.newPar,
endPar = _oldbase.endPar,
newPage = _oldbase.newPage,
endPage = _oldbase.endPage,
finish = _oldbase.finish
})

return base
Loading

0 comments on commit 9f23a1d

Please sign in to comment.