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

sile-typesetter / sile / 9400953783

06 Jun 2024 12:32PM UTC coverage: 62.819% (-11.3%) from 74.124%
9400953783

push

github

alerque
Merge branch 'develop'

1752 of 2644 new or added lines in 109 files covered. (66.26%)

2019 existing lines in 84 files now uncovered.

10830 of 17240 relevant lines covered (62.82%)

3306.33 hits per line

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

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

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

6
local _currentMaster
7

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

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

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

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

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

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

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

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

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

114
   self:registerCommand("switch-master", function (options, _)
18✔
115
      SU.required(options, "id", "switching master")
1✔
116
      self.class:switchMaster(options.id)
1✔
117
   end, "Switches the master for the current page")
10✔
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
]]
9✔
128

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