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

sile-typesetter / sile / 5913454052

19 Aug 2023 08:49PM UTC coverage: 54.288% (-20.1%) from 74.359%
5913454052

push

github

web-flow
Merge bb71e7fce into c8a15fb85

8469 of 15600 relevant lines covered (54.29%)

6468.28 hits per line

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

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

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

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

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

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

28
function package:_post_init ()
8✔
29
  self._initialized = true
29✔
30
end
31

32
function package.declareSettings (_) end
33✔
33

34
function package.registerRawHandlers (_) end
37✔
35

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

40
function package.registerCommands (_) end
8✔
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)
8✔
45
  self.class:registerCommand(name, func, help, pack)
137✔
46
end
47
function package:registerRawHandler (format, callback)
8✔
48
  self.class:registerRawHandler(format, callback)
×
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)
8✔
54
  self.class[name] = func
24✔
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.]]
8✔
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.]]
8✔
70

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

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

88
  if not notable then
40✔
89
    self.exports[name] = function (...)
40✔
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
8✔
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