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

sile-typesetter / sile / 6941442205

21 Nov 2023 08:56AM UTC coverage: 63.58% (+1.3%) from 62.266%
6941442205

Pull #1904

github

web-flow
Merge pull request #1891 from sile-typesetter/ot-tate
Pull Request #1904: Merge develop into master (commit to next release being breaking)

67 of 198 new or added lines in 20 files covered. (33.84%)

171 existing lines in 13 files now uncovered.

9907 of 15582 relevant lines covered (63.58%)

6710.82 hits per line

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

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

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

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

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

17
local settingDeclarations = { }
45✔
18
local rawhandlerRegistrations = {}
45✔
19
local commandRegistrations = { }
45✔
20

21
function package:_init (_, reload)
45✔
22
  self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
257✔
23
  if not self.class then
257✔
24
    SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
×
25
  end
26
  self.basedir = script_path()
514✔
27
  -- Note string.format(%p) would be nicer than tostring() but only LuaJIT and Lua 5.4 support it
28
  local settingsDeclarator = tostring(self.declareSettings)
257✔
29
  if reload or not settingDeclarations[settingsDeclarator] then
257✔
30
    settingDeclarations[settingsDeclarator] = true
65✔
31
    self:declareSettings()
65✔
32
  end
33
  local rawhandlerRegistrator = tostring(self.registerRawHandlers)
257✔
34
  if reload or not rawhandlerRegistrations[rawhandlerRegistrator] then
257✔
35
    rawhandlerRegistrations[rawhandlerRegistrator] = true
47✔
36
    self:registerRawHandlers()
47✔
37
  end
38
  local commandRegistrator = tostring(self.registerCommands)
257✔
39
  if reload or not commandRegistrations[commandRegistrator] then
257✔
40
    commandRegistrations[commandRegistrator] = true
237✔
41
    self:registerCommands()
237✔
42
  end
43
end
44

45
function package:_post_init ()
45✔
46
  self._initialized = true
257✔
47
end
48

49
function package.declareSettings (_) end
90✔
50

51
function package.registerRawHandlers (_) end
90✔
52

53
function package:loadPackage (packname, options, reload)
45✔
54
  return self.class:loadPackage(packname, options, reload)
94✔
55
end
56

57
function package:reloadPackage (packname, options)
45✔
NEW
58
  return self.class:reloadPackage(packname, options)
×
59
end
60

61
function package.registerCommands (_) end
53✔
62

63
-- This gives us a hook to match commands with the packages that registered
64
-- them as opposed to core commands or class-provided commands
65
function package:registerCommand (name, func, help, pack)
45✔
66
  self.class:registerCommand(name, func, help, pack)
1,073✔
67
end
68
function package:registerRawHandler (format, callback)
45✔
69
  self.class:registerRawHandler(format, callback)
2✔
70
end
71

72
-- Using this rather than doing the work directly will give us a way to
73
-- un-export them if we ever need to unload modules and revert functions
74
function package:export (name, func)
45✔
75
  self.class[name] = func
261✔
76
end
77

78
-- Shims for two possible kinds of legacy exports: blind direct stuffing into
79
-- the class but not expecting to be called as a method AND the exports table
80
-- to package modules...
81

82
local _deprecate_class_funcs = [[
83
  Please explicitly use functions provided by packages by referencing
84
  them in the document class's list of loaded packages rather than the
85
  legacy solution that added non-method functions to the class.]]
45✔
86

87
local _deprecate_exports_table = [[
88
  Please explicitly use functions provided by packages by referencing
89
  them in the document class's list of loaded packages rather than the
90
  legacy solution of calling them from an exports table.]]
45✔
91

92
function package:deprecatedExport (name, func, noclass, notable)
45✔
93

94
  if not noclass then
281✔
95
    self.class[name] = function (...)
281✔
96
      -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
97
      local inputs = {...}
4✔
98
      -- local inputs = table.unpack({...}, 1, select("#", ...))
99
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "class" then
4✔
100
        table.insert(inputs, 1, self.class)
×
101
      end
102
      SU.deprecated(("class.%s"):format(name),
8✔
103
                    ("class.packages.%s:%s"):format(self._name, name),
4✔
104
                    "0.14.0", "0.16.0", _deprecate_class_funcs)
4✔
105
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
4✔
106
    end
107
  end
108

109
  if not notable then
281✔
110
    self.exports[name] = function (...)
281✔
111
      local inputs = {...}
×
112
      if type(inputs[1]) ~= "table" or inputs[1].type ~= "package" then
×
113
        table.insert(inputs, 1, self)
×
114
      end
115
      SU.deprecated(("require('packages.%s').exports.%s"):format(self._name, name),
×
116
                    ("class.packages.%s:%s"):format(self._name, name),
×
117
                    "0.14.0", "0.16.0", _deprecate_exports_table)
×
118
      return func(table.unpack(inputs, 1, select("#", ...) + 1))
×
119
    end
120
  end
121

122
end
123

124
return package
45✔
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