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

sile-typesetter / sile / 6916312961

18 Nov 2023 09:12PM UTC coverage: 62.199% (-6.6%) from 68.751%
6916312961

push

github

web-flow
Merge a29a0997b into f64e235fa

9647 of 15510 relevant lines covered (62.2%)

6520.8 hits per line

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

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

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

6
local _currentMaster
7

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

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

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

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

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

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

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

86
function package:registerCommands ()
4✔
87

88
  self:registerCommand("define-master-template", function(options, content)
8✔
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 = SILE.scratch.masters[options.id].frames[options["first-content-frame"]]
×
103
    SILE.documentState.thisPageTemplate.frames = spare
×
104
    SILE.frames = sp2
×
105
  end)
106

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

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

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
]]
4✔
128

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