Difference between revisions of "Module:State tournaments box"
Jump to navigation
Jump to search
Pepperonipi (talk | contribs) (first test) |
m (Added `id='state-tournaments-box'` to make Comprehensive Tournaments List more robust.) |
||
(17 intermediate revisions by one other user not shown) | |||
Line 5: | Line 5: | ||
function p.main(frame) | function p.main(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
− | table = "<table>" | + | table = "<table class='wikitable' style='width: 80%;' id='state-tournaments-box'>" |
header = "<tr><th>Name</th><th>Type</th><th>Date</th><th>Division</th><th>Format</th></tr>" | header = "<tr><th>Name</th><th>Type</th><th>Date</th><th>Division</th><th>Format</th></tr>" | ||
+ | table = table .. header | ||
finalStr = "" | finalStr = "" | ||
− | + | maxRow = 1 | |
− | + | for k, v in pairs(args) do | |
− | + | num = tonumber(string.match(k, '%d+')) | |
− | + | if num > maxRow then | |
− | + | maxRow = num | |
− | + | end | |
− | + | end | |
− | + | for i = 1,maxRow do | |
− | + | table = table .. "<tr>" | |
− | + | terms = {"name", "type", "date", "div", "format"} | |
− | + | for f = 1,#terms do | |
− | + | found = false | |
− | + | for k, v in pairs(args) do | |
− | + | if string.find(k, terms[f]) ~= nil and string.match(k, '%d+') == tostring(i) then | |
− | |||
− | |||
− | |||
table = table .. "<td>" .. v .. "</td>" | table = table .. "<td>" .. v .. "</td>" | ||
+ | found = true | ||
+ | break | ||
end | end | ||
+ | end | ||
+ | if not found then | ||
+ | table = table .. "<td></td>" | ||
end | end | ||
end | end | ||
− | + | table = table .. "</tr>" | |
− | |||
− | |||
end | end | ||
table = table .. "</table>" | table = table .. "</table>" |
Revision as of 17:47, 26 September 2020
Documentation for this module may be created at Module:State tournaments box/doc
local p = {};
local getArgs = require('Module:Arguments').getArgs
local stringMod = require('Module:String')
function p.main(frame)
local args = getArgs(frame)
table = "<table class='wikitable' style='width: 80%;' id='state-tournaments-box'>"
header = "<tr><th>Name</th><th>Type</th><th>Date</th><th>Division</th><th>Format</th></tr>"
table = table .. header
finalStr = ""
maxRow = 1
for k, v in pairs(args) do
num = tonumber(string.match(k, '%d+'))
if num > maxRow then
maxRow = num
end
end
for i = 1,maxRow do
table = table .. "<tr>"
terms = {"name", "type", "date", "div", "format"}
for f = 1,#terms do
found = false
for k, v in pairs(args) do
if string.find(k, terms[f]) ~= nil and string.match(k, '%d+') == tostring(i) then
table = table .. "<td>" .. v .. "</td>"
found = true
break
end
end
if not found then
table = table .. "<td></td>"
end
end
table = table .. "</tr>"
end
table = table .. "</table>"
return table
end
return p;