-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbbrLink.lua
More file actions
83 lines (61 loc) · 2.58 KB
/
AbbrLink.lua
File metadata and controls
83 lines (61 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--[[
This module creates a link to an arbitrary page that displays the passed
abbreviation in a specified color, or every abbreviation in the game color.
The abbreviations can be specified as the name of the called function. Extra
abbreviations can be added as the "games" argument, as a space-separated list.
The color can be specified as its name in the Colore module, or as an
hexadecimal. In the case of named colors, a shade can be passed, defaulting to
'normale'
Examples:
{{#invoke: AbbrLink | RZS | Sala Antica }}
{{#invoke: AbbrLink | RZS | Sala Antica | 772299 }}
{{#invoke: AbbrLink | RZS | Sala Antica | smeraldo }}
{{#invoke: AbbrLink | RZS | Sala Antica | smeraldo | dark }}
{{#invoke: AbbrLink | RZS | games = ROZA XY | Sala Antica }}
{{#invoke: AbbrLink | RZS | games = ROZA XY | Sala Antica | 772299 }}
{{#invoke: AbbrLink | RZS | games = ROZA XY | Sala Antica | smeraldo }}
{{#invoke: AbbrLink | RZS | games = ROZA XY | Sala Antica | smeraldo | dark }}
If the first abbreviation is not constant, for example if it's a parameter in a
template, the above calls don't work. In that case, you can use the _abbr
function to pass all the abbreviations in the "games" argument:
{{#invoke: AbbrLink | _abbr | games = {{{1}}} | Sala Antica | smeraldo }}
--]]
-- stylua: ignore start
local txt = require('Wikilib-strings')
local lib = require('Wikilib-sigle')
local w = require('Wikilib')
-- stylua: ignore end
--[[
Creates the text to be displayed for an abbreviation data, that is, the
abbreviations of its games boldened and in the specified color.
If the color is not passed, it defaults to the games color. If the shade is
not given, 'normale' is used.
--]]
local makeText = function(data, args)
local color, shade = args[2], args[3]
return table.concat(lib.coloredAbbrs(data, lib.bolden, color, shade))
end
--[[
Creates the link after the processing of the abbreviations. The test to be
displayed is passed as a table in the second argument, while the link as the
first item in the first argument.
--]]
local makeLink = function(args, text)
return txt.interp("[[${link}|${text}]]", {
link = args[1],
text = table.concat(text),
})
end
-- Dynamically generates lua and wikicode interfaces
local al = lib.makeLuaAndWikicode(function(_, abbr)
local lua = lib.onMergedAbbrsArgs(abbr, "games", makeText, makeLink)
-- Not standard from Wikilib, it is necessary not to unpack
local wikicode = function(frame)
local p = w.trimAll(frame.args)
return lua(p)
end
return lua, wikicode
end)
-- Adding _abbr proxy function
lib.proxy(al, "games")
return al