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

sile-typesetter / sile / 6915746301

18 Nov 2023 07:02PM UTC coverage: 56.433% (-12.3%) from 68.751%
6915746301

push

github

web-flow
Merge 8b3fdc301 into f64e235fa

8729 of 15468 relevant lines covered (56.43%)

932.75 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")
2✔
2

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

6
local _currentMaster
7

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

24
local function defineMasters (class, list)
25
  if list then
2✔
26
    for i = 1, #list do
4✔
27
      defineMaster(class, list[i])
2✔
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)
2✔
72
  base._init(self, options)
2✔
73
  if not SILE.scratch.masters then
2✔
74
    SILE.scratch.masters = {}
2✔
75
  end
76
  self:export("switchMasterOnePage", switchMasterOnePage)
2✔
77
  self:export("switchMaster", switchMaster)
2✔
78
  self:export("defineMaster", defineMaster)
2✔
79
  self:export("defineMasters", defineMasters)
2✔
80
  self:export("currentMaster", currentMaster)
2✔
81
  if options then
2✔
82
    self.class:defineMasters(options)
2✔
83
  end
84
end
85

86
function package:registerCommands ()
2✔
87

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 = 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, _)
4✔
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")
2✔
112

113
  self:registerCommand("switch-master", function (options, _)
4✔
114
    SU.required(options, "id", "switching master")
×
115
    self.class:switchMaster(options.id)
×
116
  end, "Switches the master for the current page")
2✔
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
]]
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