-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPrevNext.lua
254 lines (217 loc) · 8.2 KB
/
PrevNext.lua
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
--[=[
TODO: refator this because it's a mess
Base module to build a PrevNext, the navigation bar at the top of a page
linking previous and next elements (whatever this means in a specific context).
Exports both a Lua and a WikiCode interface in order to work as the base class
in both environments.
To invoke this module from WikiCode the syntax is almost the same as
template:PrevNext.
{{#invoke: PrevNext | PrevNext | <args> }}
Arguments are (in Italian, copied from the template):
- colorscheme: colore, preso dal [[Modulo:Colorscheme|colorscheme]]
- color e color2: per usare colori del [[Modulo:Colore|modulo colore]]
invece di quelli del colorscheme (facoltativo il secondo)
- prev: elemento precedente, da omettere se non presente
- prevlink: se deve linkare da un'altra parte (facoltativo)
- prevspr: se va mostrato un MiniSprite, numero di Dex di quest'ultimo
(compresa eventuale sigla della forma)
- prevsup: per mostrare un eventuale [[Modulo:Sup|sup]] di fianco alla voce
(le sigle utilizzabili sono elencate in [[Modulo:Sigle/data|questa pagina]])
- prevbag: ''yes'' se è uno strumento e va mostrato lo sprite della borsa
- previmg: link ad un'immagine, che sarà aggiunta as is vicino alla voce.
Se passato viene ignorato "prevspr" (ma non prevbag).
- next, nextlink, nextspr, nextsup, nextbag, nextimg: come sopra ma per
l'elemento successivo
- prev2, prevlink2, prevspr2, prevsup2, prevbag2, previmg2: per mostrare un
secondo elemento precedente (funzionano come i precedenti)
- next2, nextlink2, nextspr2, nextsup2, nextbag2, nextimg2: per mostrare un
secondo elemento successivo (funzionano come i precedenti)
- list: link dell'elemento centrale
- series: se deve mostrare altro testo
- img: per mostrare una miniimmagine ai lati dell'elemento centrale
(specificare l'estensione ed eventualmente la dimensione)
--]=]
local p = {}
-- stylua: ignore start
local txt = require('Wikilib-strings')
local w = require('Wikilib')
local css = require('Css')
local ms = require('MiniSprite')
local links = require('Links')
local sup = require("Sup-data")
-- stylua: ignore end
p.strings = {
MAIN_BOX = [=[
<div style="padding: 0.3em 0;">
<div class="flex flex-row flex-wrap flex-items-stretch flex-main-stretch roundy text-center black-text" style="padding: 0.2em; ${bg}">${prevbox}${middlebox}${nextbox}</div></div>]=],
SIDE_BOX = [=[
<div class="width-xl-30 ${class1}" style="padding: 0.2em;">
<div class="flex flex-row flex-wrap flex-items-center flex-main-center roundy height-100 ${class2}" style="padding: 0.2em;">${content}</div></div>]=],
MIDDLE_BOX = [=[
<div class="width-xl-30 width-sm-100" style="padding: 0.2em;">
<div class="flex flex-row flex-items-center flex-main-center roundy white-bg height-100" style="padding: 0.2em;">${imgpre}${list}${imgpost}</div></div>]=],
PREV_CONTENT = [=[
<div class="width-xl-100">[[${link}|←]]${spr}${bag} [[${link}|${name}]]${sup}</div>]=],
NEXT_CONTENT = [=[
<div class="width-xl-100">${spr}${bag}[[${link}|${name}]]${sup} [[${link}|→]]</div>]=],
}
--[[
Add a at the beginning or at the end of a string, depending on the
direction. If str is nil, returns nil.
Arguments:
- str: the string to add the to. If nil, the funciton returns nil
- dir: direction, either "prev" or "next" (add the resp. before and
after the string)
--]]
local addNbsp = function(str, dir)
if not str then
return nil
end
if dir == "prev" then
return " " .. str
else
return str .. " "
end
end
--[[
Creates the markup for a side of the PrevNext, ie. anything on one side of the
middle box.
Arguments:
- presence: a boolean containing whether the content is present or not
- content: a string with the whole content
--]]
p.sideBox = function(presence, content)
return txt.interp(p.strings.SIDE_BOX, {
class1 = presence and "width-sm-100" or "hidden-sm",
class2 = presence and "white-bg" or "hidden-xl",
content = presence and content,
})
end
--[[
Creates the markup for the box in the middle of the PrevNext.
Arguments:
- list: string to link the list (full WikiCode)
- img: img file name. If you don't want to show any image pass nil
--]]
p.middleBox = function(list, img)
local imglink = img and table.concat({ "[[File:", img, "]]" })
return txt.interp(p.strings.MIDDLE_BOX, {
imgpre = addNbsp(imglink, "next") or "",
list = list,
imgpost = addNbsp(imglink, "prev") or "",
})
end
--[[
Arguments (named):
- dir: either "prev" or "next", direction of the content
- name: the displayed name of the element
- link: (optional) link of the element, if nil uses the name
- spr: (optional) ndex for the MiniSprite of the element
- bag: (optional) if "yes" the element should display an image via the
template bag
- img: (optional) an image to add. If given, spr parameter is ignored (but
not bag)
- sup: (optional) abbr of the game to put in the sup
--]]
p.makeContentLine = function(args)
local interpdata = {
link = args.link or args.name,
name = args.name,
spr = addNbsp(args.img or ms.staticLua({ args.spr }), args.dir) or "",
bag = args.bag == "yes" and addNbsp(links.bag(args.name), args.dir)
or "",
sup = args.sup and sup[args.sup] or "",
}
if args.dir == "prev" then
return txt.interp(p.strings.PREV_CONTENT, interpdata)
else
return txt.interp(p.strings.NEXT_CONTENT, interpdata)
end
end
--[[
Arguments (named):
- dir: either "prev" or "next", the direction of the content
- name: name of the element
- link: (optional) link of the element
- spr:
- bag:
- img:
- sup:
- all these with a trailing 2 (optionals)
--]]
p.makeContent = function(args)
-- Args has more values, but all the values needed have the same key
local res = p.makeContentLine(args)
if args.name2 then
res = res
.. p.makeContentLine({
dir = args.dir,
name = args.name2,
link = args.link2,
spr = args.spr2,
bag = args.bag2,
img = args.img2,
sup = args.sup2,
})
end
return res
end
--[[
Lua interface.
Arguments are named because of their number. Names are the same as WikiCode
interface.
--]]
p.PrevNextLua = function(args)
local bgargs = args.color and { type = args.color, type2 = args.color2 }
or { colorscheme = args.colorscheme or "pcwiki" }
local prevpresence = args.prev and args.prev ~= "Nessuna"
local nextpresence = args.next and args.next ~= "Nessuna"
local listlink = txt.interp("[[${link}|${name}]]", {
link = args.list,
name = args.series or args.list,
})
local prevcontent = p.makeContent({
dir = "prev",
name = args.prev,
link = args.prevlink,
spr = args.prevspr,
bag = args.prevbag,
img = args.previmg,
sup = args.prevsup,
name2 = args.prev2,
link2 = args.prevlink2,
spr2 = args.prevspr2,
bag2 = args.prevbag2,
img2 = args.previmg2,
sup2 = args.prevsup2,
})
local nextcontent = p.makeContent({
dir = "next",
name = args.next,
link = args.nextlink,
spr = args.nextspr,
bag = args.nextbag,
img = args.nextimg,
sup = args.nextsup,
name2 = args.next2,
link2 = args.nextlink2,
spr2 = args.nextspr2,
bag2 = args.nextbag2,
img2 = args.nextimg2,
sup2 = args.nextsup2,
})
return txt.interp(p.strings.MAIN_BOX, {
bg = css.horizGradLua(bgargs),
prevbox = p.sideBox(prevpresence, prevcontent),
nextbox = p.sideBox(nextpresence, nextcontent),
middlebox = p.middleBox(listlink, args.img),
})
end
--[[
WikiCode interface. Documented in the file comment.
--]]
p.PrevNext = function(frame)
return p.PrevNextLua(w.emptyStringToNil(frame.args, txt.trim))
end
p.prevnext = p.PrevNext
return p