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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

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

8173 of 15470 relevant lines covered (52.83%)

6562.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()
7✔
2
package.type = "package"
7✔
3
package._name = "base"
7✔
4

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

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

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

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

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

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

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

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

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

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

73
  if not noclass then
35✔
74
    self.class[name] = function (...)
35✔
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
35✔
89
    self.exports[name] = function (...)
35✔
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
7✔
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

© 2025 Coveralls, Inc