• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 4724920295

pending completion
4724920295

push

github

GitHub
Merge 9ac8a069b into 5c9805b8b

4 of 4 new or added lines in 3 files covered. (100.0%)

11714 of 15687 relevant lines covered (74.67%)

7016.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.69
/packages/base.lua
1
local package = pl.class()
172✔
2
package.type = "package"
172✔
3
package._name = "base"
172✔
4

5
package._initialized = false
172✔
6
package.class = nil
172✔
7

8
-- For shimming packages that used to have legacy exports
9
package.exports = {}
172✔
10

11
local function script_path ()
12
  local src = debug.getinfo(3, "S").source:sub(2)
1,087✔
13
  local base = src:match("(.*[/\\])")
1,087✔
14
  return base
1,087✔
15
end
16

17
function package:_init (_)
172✔
18
  self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
1,087✔
19
  if not self.class then
1,087✔
20
    SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
×
21
  end
22
  self.basedir = script_path()
2,174✔
23
  self:declareSettings()
1,087✔
24
  self:registerRawHandlers()
1,087✔
25
  self:registerCommands()
1,087✔
26
end
27

28
function package:_post_init ()
172✔
29
  self._initialized = true
1,088✔
30
end
31

32
function package.declareSettings (_) end
1,195✔
33

34
function package.registerRawHandlers (_) end
1,255✔
35

36
function package:loadPackage (packname)
172✔
37
  return self.class:loadPackage(packname)
412✔
38
end
39

40
function package.registerCommands (_) end
228✔
41

42
-- This gives us a hook to match commands with the packages that registered
43
-- them as opposed to core commands or class-provided commands
44
function package:registerCommand (name, func, help, pack)
172✔
45
  self.class:registerCommand(name, func, help, pack)
4,876✔
46
end
47
function package:registerRawHandler (format, callback)
172✔
48
  self.class:registerRawHandler(format, callback)
4✔
49
end
50

51
-- Using this rather than doing the work directly will give us a way to
52
-- un-export them if we ever need to unload modules and revert functions
53
function package:export (name, func)
172✔
54
  self.class[name] = func
1,104✔
55
end
56

57
-- Shims for two possible kinds of legacy exports: blind direct stuffing into
58
-- the class but not expecting to be called as a method AND the exports table
59
-- to package modules...
60

61
local _deprecate_class_funcs = [[
62
  Please explicitly use functions provided by packages by referencing
63
  them in the document class's list of loaded packages rather than the
64
  legacy solution that added non-method functions to the class.]]
172✔
65

66
local _deprecate_exports_table = [[
67
  Please explicitly use functions provided by packages by referencing
68
  them in the document class's list of loaded packages rather than the
69
  legacy solution of calling them from an exports table.]]
172✔
70

71
function package:deprecatedExport (name, func, noclass, notable)
172✔
72

73
  if not noclass then
1,134✔
74
    self.class[name] = function (...)
1,134✔
75
      -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
76
      local inputs = {...}
18✔
77
      -- local inputs = table.unpack({...}, 1, select("#", ...))
78
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "class" then
18✔
79
        table.insert(inputs, 1, self.class)
×
80
      end
81
      SU.deprecated(("class.%s"):format(name),
36✔
82
                    ("class.packages.%s:%s"):format(self._name, name),
18✔
83
                    "0.14.0", "0.16.0", _deprecate_class_funcs)
18✔
84
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
18✔
85
    end
86
  end
87

88
  if not notable then
1,134✔
89
    self.exports[name] = function (...)
1,134✔
90
      local inputs = {...}
×
91
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "package" then
×
92
        table.insert(inputs, 1, self)
×
93
      end
94
      SU.deprecated(("require('packages.%s').exports.%s"):format(self._name, name),
×
95
                    ("class.packages.%s:%s"):format(self._name, name),
×
96
                    "0.14.0", "0.16.0", _deprecate_exports_table)
×
97
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
×
98
    end
99
  end
100

101
end
102

103
return package
172✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc