Module:Sandbox: Difference between revisions
From Fanon Wiki
mNo edit summary |
mNo edit summary |
||
Line 13: | Line 13: | ||
end | end | ||
local result = {} | local result = {} | ||
table.insert(result, ' <div class="infobox" style="border-color: '.. c1 ..'"><div class="p-1 fs | table.insert(result, ' <div class="infobox" style="border-color: '.. c1 ..'"><div class="p-1 fs-2 br-4 text-center" style="background:'.. c1 ..'; color: '.. c2 ..'; grid-column: span 4">'.. title ..'</div> ') | ||
local i = 1 | local i = 1 | ||
local x = 1 | local x = 1 |
Revision as of 20:24, 8 May 2022
A sandbox for testing lua modules. Since this is a module, it uses actual programming code instead of wiki formatting.
local p = {}
function p.main(frame)
local c1, c2, title
c1 = mw.text.trim(frame.args["color"]) or "#ff8100"
c2 = mw.text.trim(frame.args["text"]) or "#000"
title = frame.args["title"]
local items = frame.args[1]
if items ~= nil then
items = mw.text.split(items, "\n")
else
items = {}
end
local result = {}
table.insert(result, ' <div class="infobox" style="border-color: '.. c1 ..'"><div class="p-1 fs-2 br-4 text-center" style="background:'.. c1 ..'; color: '.. c2 ..'; grid-column: span 4">'.. title ..'</div> ')
local i = 1
local x = 1
local y = 2
local item = {}
local parents = {}
local resultItems = ""
local resultSection = ""
local resultForm = ""
while items[i] do
item = mw.text.split(items[i], "/")
if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then
x = 1
resultItems = ""
while parents[x] do
resultItems = resultItems .. parents[x]
x = x + 1
end
y = 2
resultSection = mw.text.trim(item[1])
resultForm = mw.text.trim(item[2] or "N/A")
resultExt = mw.text.trim(item[3] or "split")
table.insert(result, '<div class="p-1 infobox-head infobox-'.. resultExt ..'" style="background:'.. c1 ..'; color:'.. c2 ..'">'.. resultSection ..'</div><div class="p-1 infobox-cell infobox-'.. resultExt ..'">'.. resultForm ..'</div>')
end
i = i + 1
end
table.insert(result, "</div>")
return table.concat(result, "")
end
return p