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

sile-typesetter / sile / 9441244789

10 Jun 2024 01:45AM UTC coverage: 49.048% (-11.6%) from 60.675%
9441244789

push

github

web-flow
Merge 8a4989eae into 519864108

8320 of 16963 relevant lines covered (49.05%)

1813.12 hits per line

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

0.0
/packages/masters/init.lua
1
local base = require("packages.base")
×
2

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

6
local _currentMaster
7

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

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

33
local function doswitch (frames)
34
   SILE.frames = { page = SILE.frames.page }
×
35
   for id, frame in pairs(frames) do
×
36
      SILE.frames[id] = frame
×
37
      frame:invalidate()
×
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
×
56
      SU.deprecated("class.switchMaster", "class:switchMaster", "0.13.0", "0.15.0")
×
57
   end
58
   _currentMaster = id
×
59
   if not SILE.scratch.masters[id] then
×
60
      SU.error("Can't find master " .. id)
×
61
   end
62
   class.pageTemplate = SILE.scratch.masters[id]
×
63
   SILE.documentState.thisPageTemplate = class.pageTemplate
×
64
   doswitch(SILE.scratch.masters[id].frames)
×
65
   SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
×
66
end
67

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

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

87
function package:registerCommands ()
×
88
   self:registerCommand("define-master-template", function (options, content)
×
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, _)
×
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")
×
113

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

129
return package
×
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