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

sile-typesetter / sile / 6934957716

20 Nov 2023 07:35PM UTC coverage: 57.468% (-3.2%) from 60.703%
6934957716

push

github

web-flow
Merge c91d9a7d4 into 34e2e5335

60 of 79 new or added lines in 1 file covered. (75.95%)

717 existing lines in 27 files now uncovered.

8957 of 15586 relevant lines covered (57.47%)

5715.38 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

61
function package.registerCommands (_) end
15✔
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)
13✔
66
  self.class:registerCommand(name, func, help, pack)
286✔
67
end
68
function package:registerRawHandler (format, callback)
13✔
UNCOV
69
  self.class:registerRawHandler(format, callback)
×
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)
13✔
75
  self.class[name] = func
69✔
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.]]
13✔
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.]]
13✔
91

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

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

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