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

sile-typesetter / sile / 14860011647

06 May 2025 12:44PM UTC coverage: 67.057% (+32.5%) from 34.559%
14860011647

push

github

alerque
chore(typesetters): Fixup access to class from typesetter functions

7 of 7 new or added lines in 2 files covered. (100.0%)

1344 existing lines in 103 files now uncovered.

14880 of 22190 relevant lines covered (67.06%)

11549.16 hits per line

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

42.0
/core/use.lua
1
local function suggest_luarocks (module)
2
   local guessed_module_name = module:gsub(".*%.", "") .. ".sile"
×
3
   return ([[
×
4

5
      If the expected module is a 3rd party extension you may need to install
6
      it using LuaRocks. The details of how to do this are highly dependent on
7
      your system and preferred installation method, but as an example
8
      installing a 3rd party SILE module to a project-local tree where might
9
      look like this:
10

11
        luarocks --lua-version %s --tree lua_modules install %s
12

13
      This will install the LuaRock(s) to your project. Note this takes
14
      advantage of the fact that SILE checks for modules in the path
15
      'lua_modules' relative to the current input file by default. SILE also
16
      automatically checks the default system Lua path by default, so using
17
      `--global` will also work.
18

19
      In the event you use a different path to the LuaRocks tree, you must also
20
      set an environment variable to teach SILE about how to find the tree
21
      *before* it runs. This can be aided by asking LuaRocks to come up with a
22
      path and evaling the result in the shell before running SILE. This only
23
      needs to be done once in each shell, (obviously substituting 'path' for
24
      your actual path):
25

26
        eval $(luarocks --lua-version %s --tree path)
27

28
      Thereafter running `sile` as normal in the same shell should work as
29
      expected. This code can be used in your shell's initialization script
30
      to avoid having to do it manually in each new shell. This is true for
31
      user home directory installations using `--local` or any specific values
32
      for `--tree` other than 'lua_modules'.
33

34
      As an anternative to setting up environment variables when using a
35
      non-default tree location, you can use the `--luarocks-tree` option to
36
      add path(s) at runtime. This is simpler to type, but must be used on each
37
      and every invocation. The value for tree should be the same as used when
38
      installing the LuaRock(s), or an appropriate full path to the location
39
      used by `--local` (generally "$HOME/.luarocks"):
40

41
        sile --luarocks-tree path %s
42

43
    ]]):format(SILE.lua_version, guessed_module_name, SILE.lua_version, pl.stringx.join(" ", _G.arg or {}))
×
44
end
45

46
local function use (module, options, reload)
47
   local status, pack
48
   if type(module) == "string" then
204✔
49
      if module:match("/") then
203✔
50
         SU.warn(([[
×
51
            Module names should not include platform-specific path separators
52

53
            Using slashes like '/' or '\' in a module name looks like a path segment. This
54
            may appear to work in some cases, but breaks cross platform compatibility.
55
            Even on the platform with the matching separator, this can lead to packages
56
            getting loaded more than once because Lua will cache one each of the different
57
            formats. Please use '.' separators which are automatically translated to the
58
            correct platform one. For example a correct use statement would be:
59

60
              \use[module=%s] instead of \use[module=%s].
61
         ]]):format(module:gsub("/", "."), module))
×
62
      end
63
      status, pack = pcall(require, module)
203✔
64
      if not status then
203✔
65
         SU.error(
×
66
            ("Unable to use '%s':\n%s%s"):format(
×
67
               module,
68
               SILE.traceback and ("    Lua " .. pack) or "",
×
69
               suggest_luarocks(module)
×
70
            )
71
         )
72
      end
73
   elseif type(module) == "table" then
1✔
74
      pack = module
1✔
75
   end
76
   local name = pack._name
204✔
77
   local class = SILE.documentState.documentClass
204✔
78
   if not pack.type then
204✔
79
      SU.error("Modules must declare their type")
×
80
   elseif pack.type == "class" then
204✔
81
      SILE.classes[name] = pack
×
82
      if class then
×
83
         SU.error("Cannot load a class after one is already instantiated")
×
84
      end
85
      SILE.scratch.class_from_uses = pack
×
86
   elseif pack.type == "inputter" then
204✔
87
      SILE.inputters[name] = pack
×
88
      SILE.inputter = pack(options)
×
89
   elseif pack.type == "outputter" then
204✔
90
      SILE.outputters[name] = pack
×
91
      SILE.outputter = pack(options)
×
92
   elseif pack.type == "shaper" then
204✔
93
      SILE.shapers[name] = pack
×
94
      SILE.shaper = pack(options)
×
95
   elseif pack.type == "typesetter" then
204✔
96
      SILE.typesetters[name] = pack
×
97
      SILE.typesetter = pack(options)
×
98
   elseif pack.type == "linebreaker" then
204✔
99
      SILE.linebreakers[name] = pack
×
100
      if SILE.typesetter then
×
UNCOV
101
         SILE.typesetter.linebreaker = pack(options)
×
102
      end
103
   elseif pack.type == "pagebuilder" then
204✔
UNCOV
104
      SILE.pagebuilders[name] = pack
×
UNCOV
105
      if SILE.typesetter then
×
106
         SILE.typesetter.pagebuilder = pack(options)
×
107
      end
108
   elseif pack.type == "package" then
204✔
109
      SILE.packages[pack._name] = pack
204✔
110
      if class then
204✔
111
         class:loadPackage(pack, options, reload)
408✔
112
      else
UNCOV
113
         table.insert(SILE.input.preambles, { pack = pack, options = options })
×
114
      end
115
   end
116
end
117

118
return use
302✔
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