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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 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 (_, args)
9
  SU.required(args, "id", "defining master")
×
10
  SU.required(args, "frames", "defining master")
×
11
  SU.required(args, "firstContentFrame", "defining master")
×
12
  SILE.scratch.masters[args.id] = { frames = {}, firstContentFrame = nil }
×
13
  for frame, spec in pairs(args.frames) do
×
14
    spec.id = frame
×
15
    if spec.solve then
×
16
      SILE.scratch.masters[args.id].frames[frame] = spec
×
17
    else
18
      SILE.scratch.masters[args.id].frames[frame] = SILE.newFrame(spec)
×
19
    end
20
  end
21
  SILE.scratch.masters[args.id].firstContentFrame = SILE.scratch.masters[args.id].frames[args.firstContentFrame]
×
22
end
23

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

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

40
local function switchMasterOnePage (class, id)
41
  if not id then
×
42
    id = class
×
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
    id, class = class, SILE.documentState.documentClass
×
57
    SU.deprecated("class.switchMaster", "class:switchMaster", "0.13.0", "0.15.0")
×
58
  end
59
  _currentMaster = id
×
60
  if not SILE.scratch.masters[id] then
×
61
    SU.error("Can't find master "..id)
×
62
  end
63
  class.pageTemplate = SILE.scratch.masters[id]
×
64
  SILE.documentState.thisPageTemplate = class.pageTemplate
×
65
  doswitch(SILE.scratch.masters[id].frames)
×
66
  SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
×
67
end
68

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

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

88
function package:registerCommands ()
×
89

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

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

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

120
end
121

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

131
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

© 2025 Coveralls, Inc