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

sile-typesetter / sile / 7232859119

16 Dec 2023 03:49PM UTC coverage: 66.878% (-7.7%) from 74.62%
7232859119

push

github

web-flow
Merge 05d75c2a3 into 8686730e4

0 of 4 new or added lines in 1 file covered. (0.0%)

1201 existing lines in 56 files now uncovered.

10550 of 15775 relevant lines covered (66.88%)

3347.52 hits per line

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

61.63
/classes/book.lua
1
local plain = require("classes.plain")
14✔
2

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

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

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

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

81
function class:finish ()
14✔
82
  local ret = plain.finish(self)
14✔
83
  return ret
14✔
84
end
85

86
function class:registerCommands ()
14✔
87

88
  plain.registerCommands(self)
14✔
89

90
  self:registerCommand("left-running-head", function (_, content)
28✔
UNCOV
91
    local closure = SILE.settings:wrap()
×
UNCOV
92
    SILE.scratch.headers.left = function () closure(content) end
×
93
  end, "Text to appear on the top of the left page")
14✔
94

95
  self:registerCommand("right-running-head", function (_, content)
28✔
96
    local closure = SILE.settings:wrap()
2✔
97
    SILE.scratch.headers.right = function () closure(content) end
4✔
98
  end, "Text to appear on the top of the right page")
16✔
99

100
  self:registerCommand("book:sectioning", function (options, content)
28✔
101
    local level = SU.required(options, "level", "book:sectioning")
2✔
102
    local number
103
    if SU.boolean(options.numbering, true) then
4✔
104
      SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
2✔
105
      number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
6✔
106
    end
107
    if SU.boolean(options.toc, true) then
4✔
108
      SILE.call("tocentry", { level = level, number = number }, SU.subContent(content))
4✔
109
    end
110
    if SU.boolean(options.numbering, true) then
4✔
111
      if options.msg then
2✔
UNCOV
112
        SILE.call("fluent", { number = number }, { options.msg })
×
113
      else
114
        SILE.call("show-multilevel-counter", { id = "sectioning" })
2✔
115
      end
116
    end
117
  end)
118

119
  self:registerCommand("book:chapter:post", function (_, _)
28✔
UNCOV
120
    SILE.call("par")
×
UNCOV
121
    SILE.call("noindent")
×
122
  end)
123

124
  self:registerCommand("book:section:post", function (_, _)
28✔
125
    SILE.process({ " " })
2✔
126
  end)
127

128
  self:registerCommand("book:subsection:post", function (_, _)
28✔
129
    SILE.process({ " " })
×
130
  end)
131

132
  self:registerCommand("book:left-running-head-font", function (_, content)
28✔
133
    SILE.call("font", { size = "9pt" }, content)
×
134
  end)
135

136
  self:registerCommand("book:right-running-head-font", function (_, content)
28✔
137
    SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
138
  end)
139

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

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

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

245
  self:registerCommand("book:chapterfont", function (_, content)
28✔
UNCOV
246
    SILE.settings:temporarily(function ()
×
UNCOV
247
      SILE.call("font", { weight = 800, size = "22pt" }, content)
×
248
    end)
249
  end)
250
  self:registerCommand("book:sectionfont", function (_, content)
28✔
251
    SILE.settings:temporarily(function ()
4✔
252
      SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
253
    end)
254
  end)
255

256
  self:registerCommand("book:subsectionfont", function (_, content)
28✔
257
    SILE.settings:temporarily(function ()
×
258
      SILE.call("font", { weight = 800, size = "12pt" }, content)
×
259
    end)
260
  end)
261

262
end
263

264
return class
14✔
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