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

sile-typesetter / sile / 14844751993

05 May 2025 05:31PM UTC coverage: 59.865% (+27.8%) from 32.062%
14844751993

push

github

alerque
fix(packages): Fix package reload to not call for command reregistration unless asked

1 of 1 new or added line in 1 file covered. (100.0%)

88 existing lines in 14 files now uncovered.

12962 of 21652 relevant lines covered (59.87%)

4076.32 hits per line

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

63.64
/classes/book.lua
1
--- book document class.
2
-- @use classes.book
3

4
local plain = require("classes.plain")
31✔
5

6
local class = pl.class(plain)
31✔
7
class._name = "book"
31✔
8

9
class.defaultFrameset = {
31✔
10
   content = {
31✔
11
      left = "8.3%pw",
12
      right = "86%pw",
13
      top = "11.6%ph",
14
      bottom = "top(footnotes)",
15
   },
31✔
16
   folio = {
31✔
17
      left = "left(content)",
18
      right = "right(content)",
19
      top = "bottom(footnotes)+3%ph",
20
      bottom = "bottom(footnotes)+5%ph",
21
   },
31✔
22
   runningHead = {
31✔
23
      left = "left(content)",
24
      right = "right(content)",
25
      top = "top(content)-8%ph",
26
      bottom = "top(content)-3%ph",
27
   },
31✔
28
   footnotes = {
31✔
29
      left = "left(content)",
30
      right = "right(content)",
31
      height = "0",
32
      bottom = "83.3%ph",
33
   },
31✔
34
}
31✔
35

36
function class:_init (options)
31✔
37
   plain._init(self, options)
31✔
38
   self:loadPackage("counters")
31✔
39
   self:loadPackage("masters", {
62✔
40
      {
41
         id = "right",
42
         firstContentFrame = self.firstContentFrame,
31✔
43
         frames = self.defaultFrameset,
31✔
44
      },
31✔
45
   })
46
   self:loadPackage("twoside", {
31✔
47
      oddPageMaster = "right",
48
      evenPageMaster = "left",
49
   })
50
   self:loadPackage("tableofcontents")
31✔
51
   self:loadPackage("footnotes", {
62✔
52
      insertInto = "footnotes",
53
      stealFrom = { "content" },
31✔
54
   })
55
end
56

57
function class:endPage ()
31✔
58
   if not SILE.scratch.headers.skipthispage then
66✔
59
      if self:oddPage() and SILE.scratch.headers.right then
126✔
60
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
2✔
61
            SILE.settings:toplevelState()
1✔
62
            SILE.settings:set("current.parindent", SILE.types.node.glue())
2✔
63
            SILE.settings:set("document.lskip", SILE.types.node.glue())
2✔
64
            SILE.settings:set("document.rskip", SILE.types.node.glue())
2✔
65
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
66
            SILE.process(SILE.scratch.headers.right)
1✔
67
            SILE.call("par")
1✔
68
         end)
69
      elseif not self:oddPage() and SILE.scratch.headers.left then
124✔
70
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
×
71
            SILE.settings:toplevelState()
×
72
            SILE.settings:set("current.parindent", SILE.types.node.glue())
×
73
            SILE.settings:set("document.lskip", SILE.types.node.glue())
×
74
            SILE.settings:set("document.rskip", SILE.types.node.glue())
×
75
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
76
            SILE.process(SILE.scratch.headers.left)
×
77
            SILE.call("par")
×
78
         end)
79
      end
80
   end
81
   SILE.scratch.headers.skipthispage = false
66✔
82
   return plain.endPage(self)
66✔
83
end
84

85
function class:finish ()
31✔
86
   local ret = plain.finish(self)
31✔
87
   return ret
31✔
88
end
89

90
function class:registerCommands ()
31✔
91
   plain.registerCommands(self)
31✔
92

93
   self:registerCommand("left-running-head", function (_, content)
62✔
UNCOV
94
      local closure = SILE.settings:wrap()
×
UNCOV
95
      SILE.scratch.headers.left = function ()
×
96
         closure(content)
×
97
      end
98
   end, "Text to appear on the top of the left page")
31✔
99

100
   self:registerCommand("right-running-head", function (_, content)
62✔
101
      local closure = SILE.settings:wrap()
2✔
102
      SILE.scratch.headers.right = function ()
2✔
103
         closure(content)
1✔
104
      end
105
   end, "Text to appear on the top of the right page")
33✔
106

107
   self:registerCommand("book:sectioning", function (options, content)
62✔
108
      local level = SU.required(options, "level", "book:sectioning")
2✔
109
      local number
110
      if SU.boolean(options.numbering, true) then
4✔
111
         SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
2✔
112
         number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
6✔
113
      end
114
      if SU.boolean(options.toc, true) then
4✔
115
         SILE.call("tocentry", { level = level, number = number }, SU.ast.subContent(content))
4✔
116
      end
117
      if SU.boolean(options.numbering, true) then
4✔
118
         if options.msg then
2✔
UNCOV
119
            SILE.call("fluent", { number = number }, { options.msg })
×
120
         else
121
            SILE.call("show-multilevel-counter", { id = "sectioning" })
2✔
122
         end
123
      end
124
   end)
125

126
   self:registerCommand("book:chapter:post", function (_, _)
62✔
UNCOV
127
      SILE.call("par")
×
UNCOV
128
      SILE.call("noindent")
×
129
   end)
130

131
   self:registerCommand("book:section:post", function (_, _)
62✔
132
      SILE.process({ " " })
2✔
133
   end)
134

135
   self:registerCommand("book:subsection:post", function (_, _)
62✔
136
      SILE.process({ " " })
×
137
   end)
138

139
   self:registerCommand("book:left-running-head-font", function (_, content)
62✔
140
      SILE.call("font", { size = "9pt" }, content)
×
141
   end)
142

143
   self:registerCommand("book:right-running-head-font", function (_, content)
62✔
144
      SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
145
   end)
146

147
   self:registerCommand("chapter", function (options, content)
62✔
UNCOV
148
      SILE.call("par")
×
UNCOV
149
      SILE.call("open-spread", { double = false })
×
UNCOV
150
      SILE.call("noindent")
×
UNCOV
151
      SILE.scratch.headers.right = nil
×
UNCOV
152
      SILE.call("set-counter", { id = "footnote", value = 1 })
×
UNCOV
153
      SILE.call("book:chapterfont", {}, function ()
×
UNCOV
154
         SILE.call("book:sectioning", {
×
155
            numbering = options.numbering,
156
            toc = options.toc,
157
            level = 1,
158
            msg = "book-chapter-title",
UNCOV
159
         }, content)
×
160
      end)
UNCOV
161
      local lang = SILE.settings:get("document.language")
×
UNCOV
162
      local postcmd = "book:chapter:post"
×
UNCOV
163
      if SILE.Commands[postcmd .. ":" .. lang] then
×
UNCOV
164
         postcmd = postcmd .. ":" .. lang
×
165
      end
UNCOV
166
      SILE.call("nofoliothispage")
×
UNCOV
167
      SILE.call(postcmd)
×
UNCOV
168
      SILE.call("book:chapterfont", {}, content)
×
UNCOV
169
      SILE.call("left-running-head", {}, function ()
×
170
         SILE.settings:temporarily(function ()
×
171
            SILE.call("book:left-running-head-font", {}, content)
×
172
         end)
173
      end)
UNCOV
174
      SILE.call("novbreak")
×
UNCOV
175
      SILE.call("par")
×
UNCOV
176
      SILE.call("novbreak")
×
UNCOV
177
      SILE.call("bigskip")
×
UNCOV
178
      SILE.call("novbreak")
×
179
      -- English typography (notably) expects the first paragraph under a section
180
      -- not to be indented. Frenchies, don't use this class :)
UNCOV
181
      SILE.call("noindent")
×
182
   end, "Begin a new chapter")
31✔
183

184
   self:registerCommand("section", function (options, content)
62✔
185
      SILE.call("par")
2✔
186
      SILE.call("noindent")
2✔
187
      SILE.call("bigskip")
2✔
188
      SILE.call("goodbreak")
2✔
189
      SILE.call("book:sectionfont", {}, function ()
4✔
190
         SILE.call("book:sectioning", {
4✔
191
            numbering = options.numbering,
2✔
192
            toc = options.toc,
2✔
193
            level = 2,
194
         }, content)
2✔
195
         local lang = SILE.settings:get("document.language")
2✔
196
         local postcmd = "book:section:post"
2✔
197
         if SILE.Commands[postcmd .. ":" .. lang] then
2✔
198
            postcmd = postcmd .. ":" .. lang
×
199
         end
200
         SILE.call(postcmd)
2✔
201
         SILE.process(content)
2✔
202
      end)
203
      if not SILE.scratch.counters.folio.off then
2✔
204
         SILE.call("right-running-head", {}, function ()
4✔
205
            SILE.call("book:right-running-head-font", {}, function ()
2✔
206
               SILE.call("raggedleft", {}, function ()
2✔
207
                  SILE.settings:temporarily(function ()
2✔
208
                     if SU.boolean(options.numbering, true) then
2✔
209
                        SILE.call("show-multilevel-counter", { id = "sectioning", level = 2 })
1✔
210
                        SILE.typesetter:typeset(" ")
1✔
211
                     end
212
                     SILE.process(content)
1✔
213
                  end)
214
               end)
215
            end)
216
         end)
217
      end
218
      SILE.call("par")
2✔
219
      SILE.call("novbreak")
2✔
220
      SILE.call("smallskip")
2✔
221
      SILE.call("novbreak")
2✔
222
      -- English typography (notably) expects the first paragraph under a section
223
      -- not to be indented. Frenchies, don't use this class :)
224
      SILE.call("noindent")
2✔
225
   end, "Begin a new section")
33✔
226

227
   self:registerCommand("subsection", function (options, content)
62✔
228
      SILE.call("par")
×
229
      SILE.call("noindent")
×
230
      SILE.call("medskip")
×
231
      SILE.call("goodbreak")
×
232
      SILE.call("book:subsectionfont", {}, function ()
×
233
         SILE.call("book:sectioning", {
×
234
            numbering = options.numbering,
235
            toc = options.toc,
236
            level = 3,
237
         }, content)
×
238
         local lang = SILE.settings:get("document.language")
×
239
         local postcmd = "book:subsection:post"
×
240
         if SILE.Commands[postcmd .. ":" .. lang] then
×
241
            postcmd = postcmd .. ":" .. lang
×
242
         end
243
         SILE.call(postcmd)
×
244
         SILE.process(content)
×
245
      end)
246
      SILE.call("par")
×
247
      SILE.call("novbreak")
×
248
      SILE.call("smallskip")
×
249
      SILE.call("novbreak")
×
250
      -- English typography (notably) expects the first paragraph under a section
251
      -- not to be indented. Frenchies, don't use this class :)
252
      SILE.call("noindent")
×
253
   end, "Begin a new subsection")
31✔
254

255
   self:registerCommand("book:chapterfont", function (_, content)
62✔
UNCOV
256
      SILE.call("font", { weight = 800, size = "22pt" }, content)
×
257
   end)
258

259
   self:registerCommand("book:sectionfont", function (_, content)
62✔
260
      SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
261
   end)
262

263
   self:registerCommand("book:subsectionfont", function (_, content)
62✔
264
      SILE.call("font", { weight = 800, size = "12pt" }, content)
×
265
   end)
266
end
267

268
return class
31✔
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