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

sile-typesetter / sile / 9432254829

08 Jun 2024 11:20PM UTC coverage: 60.675% (+3.5%) from 57.223%
9432254829

push

github

alerque
fix(build): Bundle all assets in source distribution

...even when configured for doing a static binary build with embedded
assets. They don't get installed, but they should be in the dist file in
case the good folks building want to configure it a different way.

10441 of 17208 relevant lines covered (60.68%)

1913.98 hits per line

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

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

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

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

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

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

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

88
function class:finish ()
7✔
89
   local ret = plain.finish(self)
7✔
90
   return ret
7✔
91
end
92

93
function class:registerCommands ()
7✔
94
   plain.registerCommands(self)
7✔
95

96
   self:registerCommand("left-running-head", function (_, content)
14✔
97
      local closure = SILE.settings:wrap()
×
98
      SILE.scratch.headers.left = function ()
×
99
         closure(content)
×
100
      end
101
   end, "Text to appear on the top of the left page")
7✔
102

103
   self:registerCommand("right-running-head", function (_, content)
14✔
104
      local closure = SILE.settings:wrap()
2✔
105
      SILE.scratch.headers.right = function ()
2✔
106
         closure(content)
1✔
107
      end
108
   end, "Text to appear on the top of the right page")
9✔
109

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

129
   self:registerCommand("book:chapter:post", function (_, _)
14✔
130
      SILE.call("par")
×
131
      SILE.call("noindent")
×
132
   end)
133

134
   self:registerCommand("book:section:post", function (_, _)
14✔
135
      SILE.process({ " " })
2✔
136
   end)
137

138
   self:registerCommand("book:subsection:post", function (_, _)
14✔
139
      SILE.process({ " " })
×
140
   end)
141

142
   self:registerCommand("book:left-running-head-font", function (_, content)
14✔
143
      SILE.call("font", { size = "9pt" }, content)
×
144
   end)
145

146
   self:registerCommand("book:right-running-head-font", function (_, content)
14✔
147
      SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
148
   end)
149

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

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

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

258
   self:registerCommand("book:chapterfont", function (_, content)
14✔
259
      SILE.settings:temporarily(function ()
×
260
         SILE.call("font", { weight = 800, size = "22pt" }, content)
×
261
      end)
262
   end)
263
   self:registerCommand("book:sectionfont", function (_, content)
14✔
264
      SILE.settings:temporarily(function ()
4✔
265
         SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
266
      end)
267
   end)
268

269
   self:registerCommand("book:subsectionfont", function (_, content)
14✔
270
      SILE.settings:temporarily(function ()
×
271
         SILE.call("font", { weight = 800, size = "12pt" }, content)
×
272
      end)
273
   end)
274
end
275

276
return class
7✔
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