• 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

79.88
/classes/book.lua
1
local plain = require("classes.plain")
34✔
2

3
local class = pl.class(plain)
34✔
4
class._name = "book"
34✔
5

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

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

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

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

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

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

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

107
   self:registerCommand("book:sectioning", function (options, content)
68✔
108
      local level = SU.required(options, "level", "book:sectioning")
6✔
109
      local number
110
      if SU.boolean(options.numbering, true) then
12✔
111
         SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
6✔
112
         number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
18✔
113
      end
114
      if SU.boolean(options.toc, true) then
12✔
115
         SILE.call("tocentry", { level = level, number = number }, SU.subContent(content))
12✔
116
      end
117
      if SU.boolean(options.numbering, true) then
12✔
118
         if options.msg then
6✔
119
            SILE.call("fluent", { number = number }, { options.msg })
8✔
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 (_, _)
68✔
127
      SILE.call("par")
3✔
128
      SILE.call("noindent")
3✔
129
   end)
130

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

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

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

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

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

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

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

252
   self:registerCommand("book:chapterfont", function (_, content)
68✔
253
      SILE.settings:temporarily(function ()
16✔
254
         SILE.call("font", { weight = 800, size = "22pt" }, content)
8✔
255
      end)
256
   end)
257
   self:registerCommand("book:sectionfont", function (_, content)
68✔
258
      SILE.settings:temporarily(function ()
4✔
259
         SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
260
      end)
261
   end)
262

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

270
return class
34✔
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