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

sile-typesetter / sile / 6916366760

18 Nov 2023 09:24PM UTC coverage: 60.07% (-2.2%) from 62.266%
6916366760

Pull #1904

github

web-flow
Merge pull request #1895 from alerque/embed-resources
Pull Request #1904: Merge develop into master (commit to next release being breaking)

41 of 103 new or added lines in 14 files covered. (39.81%)

447 existing lines in 26 files now uncovered.

9312 of 15502 relevant lines covered (60.07%)

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

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

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

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

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

21
function package:_init (_, reload)
20✔
22
  self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
107✔
23
  if not self.class then
107✔
24
    SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
×
25
  end
26
  self.basedir = script_path()
214✔
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)
107✔
29
  if reload or not settingDeclarations[settingsDeclarator] then
107✔
30
    settingDeclarations[settingsDeclarator] = true
30✔
31
    self:declareSettings()
30✔
32
  end
33
  local rawhandlerRegistrator = tostring(self.registerRawHandlers)
107✔
34
  if reload or not rawhandlerRegistrations[rawhandlerRegistrator] then
107✔
35
    rawhandlerRegistrations[rawhandlerRegistrator] = true
21✔
36
    self:registerRawHandlers()
21✔
37
  end
38
  local commandRegistrator = tostring(self.registerCommands)
107✔
39
  if reload or not commandRegistrations[commandRegistrator] then
107✔
40
    commandRegistrations[commandRegistrator] = true
100✔
41
    self:registerCommands()
100✔
42
  end
43
end
44

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

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

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

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

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

61
function package.registerCommands (_) end
23✔
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)
20✔
66
  self.class:registerCommand(name, func, help, pack)
449✔
67
end
68
function package:registerRawHandler (format, callback)
20✔
69
  self.class:registerRawHandler(format, callback)
1✔
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)
20✔
75
  self.class[name] = func
106✔
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.]]
20✔
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.]]
20✔
91

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

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

109
  if not notable then
121✔
110
    self.exports[name] = function (...)
121✔
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
20✔
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