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

sile-typesetter / sile / 14958605596

11 May 2025 06:34PM UTC coverage: 31.311% (-25.4%) from 56.689%
14958605596

push

github

web-flow
Merge 3e53926d5 into 443551a3e

6301 of 20124 relevant lines covered (31.31%)

4203.99 hits per line

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

58.97
/packages/masters/init.lua
1
local base = require("packages.base")
2✔
2

3
local package = pl.class(base)
2✔
4
package._name = "masters"
2✔
5

6
local _currentMaster
7

8
local function defineMaster (_, options)
9
   SU.required(options, "id", "defining master")
2✔
10
   SU.required(options, "frames", "defining master")
2✔
11
   SU.required(options, "firstContentFrame", "defining master")
2✔
12
   SILE.scratch.masters[options.id] = { frames = {}, firstContentFrame = nil }
2✔
13
   for frame, spec in pairs(options.frames) do
10✔
14
      spec.id = frame
8✔
15
      if spec.solve then
8✔
16
         SILE.scratch.masters[options.id].frames[frame] = spec
×
17
      else
18
         SILE.scratch.masters[options.id].frames[frame] = SILE.newFrame(spec)
16✔
19
      end
20
   end
21
   SILE.scratch.masters[options.id].firstContentFrame =
2✔
22
      SILE.scratch.masters[options.id].frames[options.firstContentFrame]
2✔
23
end
24

25
local function defineMasters (class, list)
26
   if list then
2✔
27
      for i = 1, #list do
4✔
28
         defineMaster(class, list[i])
2✔
29
      end
30
   end
31
end
32

33
local function doswitch (frames)
34
   SILE.frames = { page = SILE.frames.page }
15✔
35
   for id, frame in pairs(frames) do
75✔
36
      SILE.frames[id] = frame
60✔
37
      frame:invalidate()
60✔
38
   end
39
end
40

41
local function switchMasterOnePage (_, id)
42
   if not id then
×
43
      SU.deprecated("class.switchMasterOnePage", "class:switchMasterOnePage", "0.13.0", "0.15.0")
×
44
   end
45
   if not SILE.scratch.masters[id] then
×
46
      SU.error("Can't find master " .. id)
×
47
   end
48
   SILE.documentState.thisPageTemplate = SILE.scratch.masters[id]
×
49
   doswitch(SILE.scratch.masters[id].frames)
×
50
   SILE.typesetter:chuck()
×
51
   SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
×
52
end
53

54
local function switchMaster (class, id)
55
   if not id then
15✔
56
      SU.deprecated("class.switchMaster", "class:switchMaster", "0.13.0", "0.15.0")
×
57
   end
58
   _currentMaster = id
15✔
59
   if not SILE.scratch.masters[id] then
15✔
60
      SU.error("Can't find master " .. id)
×
61
   end
62
   class.pageTemplate = SILE.scratch.masters[id]
15✔
63
   SILE.documentState.thisPageTemplate = class.pageTemplate
15✔
64
   doswitch(SILE.scratch.masters[id].frames)
15✔
65
   SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
15✔
66
end
67

68
local function currentMaster (_)
69
   return _currentMaster
×
70
end
71

72
function package:_init (options)
2✔
73
   base._init(self, options)
2✔
74
   if not SILE.scratch.masters then
2✔
75
      SILE.scratch.masters = {}
2✔
76
   end
77
   self:export("switchMasterOnePage", switchMasterOnePage)
2✔
78
   self:export("switchMaster", switchMaster)
2✔
79
   self:export("defineMaster", defineMaster)
2✔
80
   self:export("defineMasters", defineMasters)
2✔
81
   self:export("currentMaster", currentMaster)
2✔
82
   if options then
2✔
83
      self.class:defineMasters(options)
2✔
84
   end
85
end
86

87
function package:registerCommands ()
2✔
88
   self:registerCommand("define-master-template", function (options, content)
4✔
89
      SU.required(options, "id", "defining a master")
×
90
      SU.required(options, "first-content-frame", "defining a master")
×
91
      -- Subvert the <frame> functionality from baseclass
92
      local spare = SILE.documentState.thisPageTemplate.frames
×
93
      local sp2 = SILE.frames
×
94
      SILE.frames = { page = SILE.frames.page }
×
95
      SILE.documentState.thisPageTemplate.frames = {}
×
96
      SILE.process(content)
×
97
      SILE.scratch.masters[options.id] = {}
×
98
      SILE.scratch.masters[options.id].frames = SILE.documentState.thisPageTemplate.frames
×
99
      if not SILE.scratch.masters[options.id].frames[options["first-content-frame"]] then
×
100
         SU.error("first-content-frame " .. options["first-content-frame"] .. " not found")
×
101
      end
102
      SILE.scratch.masters[options.id].firstContentFrame =
×
103
         SILE.scratch.masters[options.id].frames[options["first-content-frame"]]
×
104
      SILE.documentState.thisPageTemplate.frames = spare
×
105
      SILE.frames = sp2
×
106
   end)
107

108
   self:registerCommand("switch-master-one-page", function (options, _)
4✔
109
      SU.required(options, "id", "switching master")
×
110
      self.class:switchMasterOnePage(options.id)
×
111
      SILE.typesetter:leaveHmode()
×
112
   end, "Switches the master for the current page")
2✔
113

114
   self:registerCommand("switch-master", function (options, _)
4✔
115
      SU.required(options, "id", "switching master")
×
116
      self.class:switchMaster(options.id)
×
117
   end, "Switches the master for the current page")
2✔
118
end
119

120
package.documentation = [[
121
\begin{document}
122
The masters functionality is also itself an add-on package.
123
It allows a class to define sets of frames and switch between them either temporarily or permanently.
124
It defines the commands \autodoc:command{\define-master-template} (which is patterned on the \autodoc:command{\pagetemplate} function we will meet in Chapter 8), \autodoc:command{\switch-master}, and \autodoc:command{\switch-master-one-page}.
125
See \code{tests/masters.sil} for more about this package.
126
\end{document}
127
]]
2✔
128

129
return package
2✔
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