Moduł:Brudnopis/Paweł Ziemian/LK
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Brudnopis/Paweł Ziemian/LK/opis
local icons = mw.loadData("Moduł:Brudnopis/Paweł Ziemian/LK/dane")
function Restriction(icon1, side1, side2)
if not icon1 then
return function(_) return true end
end
local borders1 = icons[icon1] or {}
local b1 = borders1[side1]
return function(icon2)
local borders2 = icons[icon2] or {}
local b2 = borders2[side2]
local result = b1 == b2
return result
end
end
function Select(T, L, B, R)
local result = {}
for k, v in pairs(icons) do
if T(k) and L(k) and B(k) and R(k) then
table.insert(result, k)
end
end
return result
end
function Przebieg(b, c)
local kod = {}
table.insert(kod, "{| class=\"wikitable\"\n")
table.insert(kod, "|+") table.insert(kod, c) table.insert(kod, "\n")
table.insert(kod, "| [[Plik:BSicon ") table.insert(kod, c) table.insert(kod, ".svg|100px]]\n")
table.insert(kod, "| style=\"padding: 0\"|\n")
table.insert(kod, "{| class=\"infobox\"\n")
table.insert(kod, "| style=\"padding: 0\"|\n")
table.insert(kod, "{| class=\"nopadding\" cellspacing=\"0\"\n")
if b.T then
table.insert(kod, "{{LK|||")
table.insert(kod, b.T)
table.insert(kod, "|||}}\n")
end
table.insert(kod, "{{LK||")
if b.L then
table.insert(kod, b.L)
end
table.insert(kod, "|")
table.insert(kod, c)
table.insert(kod, "|")
if b.R then
table.insert(kod, b.R)
end
table.insert(kod, "||")
table.insert(kod, c)
table.insert(kod, "}}\n")
if b.B then
table.insert(kod, "{{LK|||")
table.insert(kod, b.B)
table.insert(kod, "|||}}\n")
end
table.insert(kod, "|}\n")
table.insert(kod, "|}\n")
table.insert(kod, "|}\n")
return table.concat(kod, "")
end
return {
Find = function(frame)
local b = {
T = frame.args.T,
L = frame.args.L,
B = frame.args.B,
R = frame.args.R,
}
if not b.T and not b.L and not b.B and not b.R then
mw.log("Brak parametrów")
return
end
local T = Restriction(b.T, "B", "T")
local L = Restriction(b.L, "R", "L")
local B = Restriction(b.B, "T", "B")
local R = Restriction(b.R, "L", "R")
local selected = Select(T, L, B, R)
local list = {
"<templatestyles src=\"Szablon:Linia kolejowa infobox/styles.css\" />\n",
}
for _, k in ipairs(selected) do
local przebieg = Przebieg(b, k)
table.insert(list, przebieg)
end
local wikikod = table.concat(list, "")
local result = frame:preprocess(wikikod)
return result
end,
}