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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

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

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

6
local _currentMaster
7

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

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

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

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

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

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

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

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

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

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

121
package.documentation = [[
122
\begin{document}
123
The masters functionality is also itself an add-on package.
124
It allows a class to define sets of frames and switch between them either temporarily or permanently.
125
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}.
126
See \code{tests/masters.sil} for more about this package.
127
\end{document}
128
]]
37✔
129

130
return package
37✔
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