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

sile-typesetter / sile / 14361761590

09 Apr 2025 03:53PM UTC coverage: 29.317% (-31.1%) from 60.462%
14361761590

push

github

alerque
chore(deps): Bump LuaRocks dependencies to latest versions

5876 of 20043 relevant lines covered (29.32%)

4237.53 hits per line

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

74.63
/packages/base.lua
1
--- SILE package class.
2
-- @interfaces packages
3

4
local package = pl.class()
3✔
5
package.type = "package"
3✔
6
package._name = "base"
3✔
7

8
package._initialized = false
3✔
9
package.class = nil
3✔
10

11
-- For shimming packages that used to have legacy exports
12
package.exports = {}
3✔
13

14
local function script_path ()
15
   local src = debug.getinfo(3, "S").source:sub(2)
32✔
16
   local base = src:match("(.*[/\\])")
32✔
17
   return base
32✔
18
end
19

20
local settingDeclarations = {}
3✔
21
local rawhandlerRegistrations = {}
3✔
22
local commandRegistrations = {}
3✔
23

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

49
function package:_post_init ()
3✔
50
   self._initialized = true
32✔
51
end
52

53
function package:declareSettings () end
6✔
54

55
function package:registerRawHandlers () end
6✔
56

57
function package:loadPackage (packname, options, reload)
3✔
58
   return self.class:loadPackage(packname, options, reload)
13✔
59
end
60

61
function package:reloadPackage (packname, options)
3✔
62
   return self.class:reloadPackage(packname, options)
×
63
end
64

65
function package:registerCommands () end
5✔
66

67
-- This gives us a hook to match commands with the packages that registered
68
-- them as opposed to core commands or class-provided commands
69

70
--- Register a function as a SILE command.
71
-- Takes any Lua function and registers it for use as a SILE command (which will in turn be used to process any content
72
-- nodes identified with the command name.
73
--
74
-- A similar method is available for classes, `classes:registerCommand`.
75
-- @tparam string name Name of cammand to register.
76
-- @tparam function func Callback function to use as command handler.
77
-- @tparam[opt] nil|string help User friendly short usage string for use in error messages, documentation, etc.
78
-- @tparam[opt] nil|string pack Information identifying the module registering the command for use in error and usage
79
-- messages. Usually auto-detected.
80
-- @see SILE.classes:registerCommand
81
function package:registerCommand (name, func, help, pack)
3✔
82
   self.class:registerCommand(name, func, help, pack)
121✔
83
end
84
function package:registerRawHandler (format, callback)
3✔
85
   self.class:registerRawHandler(format, callback)
×
86
end
87

88
-- Using this rather than doing the work directly will give us a way to
89
-- un-export them if we ever need to unload modules and revert functions
90
function package:export (name, func)
3✔
91
   self.class[name] = func
39✔
92
end
93

94
-- Shims for two possible kinds of legacy exports: blind direct stuffing into
95
-- the class but not expecting to be called as a method AND the exports table
96
-- to package modules...
97

98
local _deprecate_class_funcs = [[
99
   Please explicitly use functions provided by packages by referencing them in
100
   the document class's list of loaded packages rather than the legacy solution
101
   that added non-method functions to the class.
102
]]
3✔
103

104
local _deprecate_exports_table = [[
105
   Please explicitly use functions provided by packages by referencing them in
106
   the document class's list of loaded packages rather than the legacy solution
107
   of calling them from an exports table.
108
]]
3✔
109

110
function package:deprecatedExport (name, func, noclass, notable)
3✔
111
   if not noclass then
29✔
112
      self.class[name] = function (...)
29✔
113
         -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
114
         local inputs = { ... }
×
115
         -- local inputs = table.unpack({...}, 1, select("#", ...))
116
         if type(inputs[1]) ~= "table" or inputs[1].type ~= "class" then
×
117
            table.insert(inputs, 1, self.class)
×
118
         end
119
         SU.deprecated(
×
120
            ("class.%s"):format(name),
×
121
            ("class.packages.%s:%s"):format(self._name, name),
×
122
            "0.14.0",
123
            "0.16.0",
124
            _deprecate_class_funcs
125
         )
126
         return func(pl.utils.unpack(inputs, 1, select("#", ...) + 1))
×
127
      end
128
   end
129

130
   if not notable then
29✔
131
      self.exports[name] = function (...)
29✔
132
         local inputs = { ... }
×
133
         if type(inputs[1]) ~= "table" or inputs[1].type ~= "package" then
×
134
            table.insert(inputs, 1, self)
×
135
         end
136
         SU.deprecated(
×
137
            ("require('packages.%s').exports.%s"):format(self._name, name),
×
138
            ("class.packages.%s:%s"):format(self._name, name),
×
139
            "0.14.0",
140
            "0.16.0",
141
            _deprecate_exports_table
142
         )
143
         return func(pl.utils.unpack(inputs, 1, select("#", ...) + 1))
×
144
      end
145
   end
146
end
147

148
return package
3✔
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