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

sile-typesetter / sile / 14390735465

10 Apr 2025 09:30PM UTC coverage: 34.559% (-31.7%) from 66.23%
14390735465

push

github

alerque
Merge tag 'v0.15.12' into develop

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

4064 existing lines in 73 files now uncovered.

6918 of 20018 relevant lines covered (34.56%)

2597.26 hits per line

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

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

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

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

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

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

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

24
function package:_init (_, reload)
62✔
25
   SU._avoid_base_class_use(self)
419✔
26
   self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
419✔
27
   if not self.class then
419✔
UNCOV
28
      SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
×
29
   end
30
   self.basedir = script_path()
838✔
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)
419✔
33
   if reload or not settingDeclarations[settingsDeclarator] then
419✔
34
      settingDeclarations[settingsDeclarator] = true
96✔
35
      self:declareSettings()
96✔
36
   end
37
   local rawhandlerRegistrator = tostring(self.registerRawHandlers)
419✔
38
   if reload or not rawhandlerRegistrations[rawhandlerRegistrator] then
419✔
39
      rawhandlerRegistrations[rawhandlerRegistrator] = true
71✔
40
      self:registerRawHandlers()
71✔
41
   end
42
   local commandRegistrator = tostring(self.registerCommands)
419✔
43
   if reload or not commandRegistrations[commandRegistrator] then
419✔
44
      commandRegistrations[commandRegistrator] = true
379✔
45
      self:registerCommands()
379✔
46
   end
47
end
48

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

53
function package:declareSettings () end
129✔
54

55
function package:registerRawHandlers () end
128✔
56

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

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

65
function package:registerCommands () end
74✔
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)
62✔
82
   self.class:registerCommand(name, func, help, pack)
1,616✔
83
end
84
function package:registerRawHandler (format, callback)
62✔
85
   self.class:registerRawHandler(format, callback)
5✔
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)
62✔
91
   self.class[name] = func
388✔
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
100
  them in the document class's list of loaded packages rather than the
101
  legacy solution that added non-method functions to the class.]]
62✔
102

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

108
function package:deprecatedExport (name, _, noclass, notable)
62✔
UNCOV
109
   if not noclass then
×
UNCOV
110
      self.class[name] = function ()
×
UNCOV
111
         SU.deprecated(
×
UNCOV
112
            ("class.%s"):format(name),
×
UNCOV
113
            ("class.packages.%s:%s"):format(self._name, name),
×
114
            "0.14.0",
115
            "0.16.0",
116
            _deprecate_class_funcs
117
         )
118
      end
119
   end
120

UNCOV
121
   if not notable then
×
UNCOV
122
      self.exports[name] = function ()
×
UNCOV
123
         SU.deprecated(
×
UNCOV
124
            ("require('packages.%s').exports.%s"):format(self._name, name),
×
UNCOV
125
            ("class.packages.%s:%s"):format(self._name, name),
×
126
            "0.14.0",
127
            "0.16.0",
128
            _deprecate_exports_table
129
         )
130
      end
131
   end
132
end
133

134
return package
62✔
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