Skip to content

Commit

Permalink
refactor(core)!: Move assorted classes from oddball names in core to …
Browse files Browse the repository at this point in the history
…types

BREAKING CHANGE: Several top level instance creaters of various names
have been re-organized under SILE.types.

Specifically SILE.color, SILE.measurement, and SILE.length have the same
names, just under SILE.types.<name>. Additionally SILE.nodefactory is
now SILE.types.node and SILE.units is not SILE.types.unit.

This brings a little bit of sanity to the naming schemes so that you can
guess how to use something from the name, but it also makes room for 3rd
party add ons to more easily extend or replace these functions. It also
makes it easier to start substituting Rust bits where desired.

reorg
  • Loading branch information
alerque committed Feb 4, 2024
1 parent 580e22f commit 8287a0f
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 224 deletions.
2 changes: 1 addition & 1 deletion build-aux/list-dist-files.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ finder () {

printf '%s' "SILEDATA ="
finder core -name '*.lua' -not -name '*_spec.lua' -not -name 'version.lua' -not -name 'features.lua' -not -name 'pathsetup.lua'
finder classes inputters languages outputters packages shapers typesetters pagebuilders -name '*.lua' -not -name '*_spec.lua'
finder classes inputters languages outputters packages shapers types typesetters pagebuilders -name '*.lua' -not -name '*_spec.lua'
finder classes i18n packages -name '*.ftl'
finder packages -name '*.svg'

Expand Down
47 changes: 47 additions & 0 deletions core/deprecations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,53 @@ SILE.readFile = function (filename)
return SILE.processFile(filename)
end

local usetypes = function (type)
SU.deprecated(("SILE.%s"):format(type), ("SILE.types.%s"):format(type), "0.15.0", "0.16.0", ([[
In order to keep things tidy internally, more easily allow 3rd party
packages to override core functions, and substitute some slow bits
with Rust modules, internal types have been moved from the top level
SILE global to a types namespace.
Please substitute 'SILE.%s()' with 'SILE.types.%s()'.
]]):format(type, type))
return SILE.types[type]
end

SILE.color = setmetatable({}, {
__call = function (_, ...) return usetypes("color")(...) end,
__index = function () return usetypes("color") end,
})

SILE.measurement = setmetatable({}, {
__call = function (_, ...) return usetypes("measurement")(...) end,
__index = function () return usetypes("measurement") end,
})

SILE.length = setmetatable({}, {
__call = function (_, ...) return usetypes("length")(...) end,
__index = function () return usetypes("length") end,
})

local usetypes2 = function (old, new, type)
SU.deprecated(("SILE.%s.%s"):format(old, type), ("SILE.types.%s.%s"):format(new, type), "0.15.0", "0.16.0", ([[
In order to keep things tidy internally, more easily allow 3rd party
packages to override core functions, and substitute some slow bits
with Rust modules, internal types have been moved from the top level
SILE global to a types namespace.
Please substitute 'SILE.%s.%s()' with 'SILE.types.%s.%s()'.
]]):format(old, type, new, type))
return SILE.types[new][type]
end

SILE.nodefactory = setmetatable({}, {
__index = function (_, type) return usetypes2("nodefactory", "node", type) end,
})

SILE.units = setmetatable({}, {
__index = function (_, type) return usetypes2("units", "unit", type) end,
})

SILE.colorparser = function (input)
SU.deprecated("SILE.colorparser", "SILE.color", "0.14.0", "0.16.0",
[[Color results are now color objects, not just tables with relevant values.]])
Expand Down
5 changes: 3 additions & 2 deletions core/parserbits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ local C, Cf, Cg, Ct, Cmt = lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.Cmt

local function isaunit (_, _, unit)
-- TODO: fix race condition so we can validate units
if not SILE or not SILE.units then return true end
return SILE.units[unit] and true or false
local factory = rawget(SILE.types, "unit")
if not SILE or not factory then return true end
return factory[unit] and true or false
end

local function inferpoints (number)
Expand Down
10 changes: 2 additions & 8 deletions core/sile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,13 @@ SILE.classes = core_loader("classes")
SILE.packages = core_loader("packages")
SILE.typesetters = core_loader("typesetters")
SILE.pagebuilders = core_loader("pagebuilders")
SILE.types = core_loader("types")

-- Internal libraries that don't make assumptions on load, only provide something
-- Internal libraries that don't try to use anything on load, only provide something
SILE.parserBits = require("core.parserbits")
SILE.frameParser = require("core.frameparser")
SILE.color = require("core.color")
SILE.units = require("core.units")
SILE.fontManager = require("core.fontmanager")

-- Internal libraries that assume globals, may be picky about load order
SILE.measurement = require("core.measurement")
SILE.length = require("core.length")
SILE.papersize = require("core.papersize")
SILE.nodefactory = require("core.nodefactory")

-- NOTE:
-- See remainaing internal libraries loaded at the end of this file because
Expand Down
2 changes: 1 addition & 1 deletion packages/math/base-elements.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local nodefactory = require("core.nodefactory")
local nodefactory = require("types.node")
local hb = require("justenoughharfbuzz")
local ot = require("core.opentype-parser")
local syms = require("packages.math.unicode-symbols")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8287a0f

Please sign in to comment.