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

sile-typesetter / sile / 11162506581

03 Oct 2024 01:02PM UTC coverage: 66.881% (-2.2%) from 69.13%
11162506581

push

github

web-flow
Merge pull request #2124 from alerque/integrate-i18n

Consolodate locale related resources in language scope

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

400 existing lines in 26 files now uncovered.

11973 of 17902 relevant lines covered (66.88%)

4807.68 hits per line

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

74.8
/packages/retrograde/init.lua
1
local base = require("packages.base")
45✔
2

3
local package = pl.class(base)
45✔
4
package._name = "retrograde"
45✔
5

6
local semver = require("semver")
45✔
7

8
local semver_descending = function (a, b)
9
   a, b = semver(a), semver(b)
138✔
10
   return a > b
92✔
11
end
12

13
-- Default settings that have gone out of fashion
14
package.default_settings = {
45✔
15
   ["0.15.0"] = {
45✔
16
      ["shaper.spaceenlargementfactor"] = 1.2,
17
      ["document.parindent"] = "20pt",
18
   },
45✔
19
   ["0.9.5"] = {
45✔
20
      ["font.family"] = "Gentium Basic",
21
   },
45✔
22
}
45✔
23

24
local function _v14_aligns (content)
25
   SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
64✔
26
   SILE.settings:set("document.parindent", SILE.types.node.glue())
64✔
27
   SILE.settings:set("document.spaceskip", SILE.types.length("1spc", 0, 0))
64✔
28
   SILE.process(content)
32✔
29
   SILE.call("par")
32✔
30
end
31

32
package.shim_commands = {
45✔
33
   ["0.15.0"] = {
45✔
34
      ["center"] = function (_)
35
         return function (_, content)
36
            if #SILE.typesetter.state.nodes ~= 0 then
32✔
37
               SU.warn("\\center environment started after other nodes in a paragraph, may not center as expected")
×
38
            end
39
            SILE.settings:temporarily(function ()
64✔
40
               SILE.settings:set("document.rskip", SILE.types.node.hfillglue())
64✔
41
               SILE.settings:set("document.lskip", SILE.types.node.hfillglue())
64✔
42
               _v14_aligns(content)
32✔
43
            end)
44
         end
45
      end,
46
      ["raggedright"] = function (_)
47
         return function (_, content)
48
            SILE.settings:temporarily(function ()
×
49
               SILE.settings:set("document.rskip", SILE.types.node.hfillglue())
×
50
               _v14_aligns(content)
×
51
            end)
52
         end
53
      end,
54
      ["raggedleft"] = function (_)
55
         return function (_, content)
UNCOV
56
            SILE.settings:temporarily(function ()
×
UNCOV
57
               SILE.settings:set("document.lskip", SILE.types.node.hfillglue())
×
UNCOV
58
               _v14_aligns(content)
×
59
            end)
60
         end
61
      end,
62
   },
45✔
63
}
45✔
64

65
package.shim_classes = {
45✔
66
   ["0.15.0"] = {
45✔
67
      ["classes.base.newPar"] = function ()
68
         local newPar = SILE.documentState.documentClass.newPar
46✔
69
         SILE.documentState.documentClass.newPar = function (typesetter)
46✔
70
            newPar(typesetter)
327✔
71
            SILE.settings:set("current.parindent", nil)
327✔
72
         end
73
         return function ()
74
            SILE.classes.book.newPar = newPar
×
75
         end
76
      end,
77
      ["classes.base.endPar"] = function ()
78
         local endPar = SILE.documentState.documentClass.endPar
46✔
79
         SILE.documentState.documentClass.endPar = function (typesetter)
46✔
80
            local current_parindent = SILE.settings:get("current.parindent")
410✔
81
            endPar(typesetter)
410✔
82
            SILE.settings:set("current.parindent", current_parindent)
410✔
83
         end
84
         return function ()
85
            SILE.classes.book.endPar = endPar
×
86
         end
87
      end,
88
   },
45✔
89
}
45✔
90

91
function package:_init (options)
45✔
92
   base._init(self, options)
46✔
93
   self:recede(options.target)
46✔
94
end
95

96
function package:recede (target)
45✔
97
   self:recede_defaults(target)
46✔
98
   self:recede_classes(target)
46✔
99
   self:recede_commands(target)
46✔
100
end
101

102
function package._prep (_, target, type)
45✔
103
   target = semver(target and target or SILE.version)
276✔
104
   SU.debug("retrograde", ("Targeting changes to %s since the release of SILE v%s."):format(type, target))
138✔
105
   local terminal = function (version)
106
      SU.debug(
92✔
107
         "retrograde",
46✔
108
         ("The next set of changes to %s is from the release of SILE v%s, stopping."):format(type, version)
46✔
109
      )
110
   end
111
   return target, terminal
138✔
112
end
113

114
function package:recede_defaults (target)
45✔
115
   local semvertarget, terminal = self:_prep(target, "defaults")
46✔
116
   for version, settings in pl.tablex.sort(self.default_settings, semver_descending) do
230✔
117
      version = semver(version)
184✔
118
      if version <= semvertarget then
92✔
119
         terminal(version)
46✔
120
         break
46✔
121
      end
122
      for parameter, value in pairs(settings) do
138✔
123
         SU.debug(
184✔
124
            "retrograde",
92✔
125
            ("Resetting '%s' to '%s' as it was prior to v%s."):format(parameter, tostring(value), version)
92✔
126
         )
127
         SILE.settings:set(parameter, value, true)
92✔
128
      end
129
   end
130
end
131

132
function package:recede_classes (target)
45✔
133
   local semvertarget, terminal = self:_prep(target, "classes")
46✔
134
   local reverters = {}
46✔
135
   for version, callbacks in pl.tablex.sort(self.shim_classes, semver_descending) do
230✔
136
      version = semver(version)
92✔
137
      if version <= semvertarget then
46✔
138
         terminal(version)
×
139
         break
140
      end
141
      for widget, callback in pairs(callbacks) do
138✔
142
         SU.debug("retrograde", ("Shimming '%s' to behavior similar to prior to v%s."):format(widget, version))
92✔
143
         local reverter = callback()
92✔
144
         reverters[widget] = reverter
92✔
145
      end
146
   end
147
   return function ()
148
      for _, reverter in pairs(reverters) do
×
149
         reverter()
×
150
      end
151
   end
152
end
153

154
function package:recede_commands (target)
45✔
155
   local semvertarget, terminal = self:_prep(target, "commands")
46✔
156
   local currents = {}
46✔
157
   for version, commands in pl.tablex.sort(self.shim_commands, semver_descending) do
230✔
158
      version = semver(version)
92✔
159
      if version <= semvertarget then
46✔
160
         terminal(version)
×
161
         break
162
      end
163
      for command, get_function in pairs(commands) do
184✔
164
         SU.debug("retrograde", ("Shimming command '%s' to behavior similar to prior to v%s."):format(command, version))
138✔
165
         local current = SILE.Commands[command]
138✔
166
         currents[command] = current
138✔
167
         SILE.Commands[command] = get_function(current)
276✔
168
      end
169
   end
170
   local function reverter ()
171
      for command, current in pairs(currents) do
×
172
         SILE.Commands[command] = current
×
173
      end
174
   end
175
   return reverter
46✔
176
end
177

178
function package:registerCommands ()
45✔
179
   self:registerCommand("recede", function (options, content)
90✔
180
      SILE.call("recede-defaults", options, content)
×
181
   end)
182

183
   self:registerCommand("recede-defaults", function (options, content)
90✔
184
      if content then
×
185
         SILE.settings:temporarily(function ()
×
186
            self:recede_defaults(options.target)
×
187
            SILE.process(content)
×
188
         end)
189
      else
190
         self:recede_defaults(options.target)
×
191
      end
192
   end)
193

194
   self:registerCommand("recede-classes", function (options, content)
90✔
195
      if content then
×
196
         SILE.settings:temporarily(function ()
×
197
            local reverter = self:recede_classes(options.target)
×
198
            SILE.process(content)
×
199
            reverter()
×
200
         end)
201
      else
202
         self:recede_classes(options.target)
×
203
      end
204
   end)
205

206
   self:registerCommand("recede-commands", function (options, content)
90✔
207
      if content then
×
208
         local reverter = self:recede_commands(options.target)
×
209
         SILE.process(content)
×
210
         reverter()
×
211
      else
212
         self:recede_commands(options.target)
×
213
      end
214
   end)
215
end
216

217
local doctarget = "v" .. tostring(semver(SILE.version))
135✔
218
package.documentation = ([[
219
\begin{document}
220

221
From time to time, the default behavior of a function or value of a setting in SILE might change with a new release.
222
If these changes are expected to cause document reflows they will be noted in release notes as breaking changes.
223
That generally means old documents will have to be updated to keep rending the same way.
224
On a best-effort basis (not a guarantee) this package tries to restore earlier default behaviors and settings.
225

226
For settings this is relatively simple.
227
You just set the old default value explicitly in your document or project.
228
But first, knowing what those are requires a careful reading of the release notes.
229
Then you have to chase down the incantations to set the old values.
230
This package tries to restore as many previous setting values as possible to make old documents render like they would have in previous releases without changing the documents themselves (beyond loading this package).
231

232
For functions things are a little more complex, but for as many cases as possible we'll try to allow swapping old versions of code.
233

234
None of this is a guarantee that your old document will be stable in new versions of SILE.
235
All of this is a danger zone.
236

237
From inside a document, use \autodoc:command{\use[module=packages.retrograde,target=%s]} to load features from SILE %s.
238

239
This can also be triggered from the command line with no changes to a document:
240

241
\begin{autodoc:codeblock}
242
$ sile -u 'packages.retrograde[target=%s]'
243
\end{autodoc:codeblock}
244

245
\end{document}
246
]]):format(doctarget, doctarget, doctarget)
45✔
247

248
return package
45✔
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