Documentation for this module may be created at Module:Track list/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function extract(str)
local col = nil
local title_col = string.match(str, "^title%d$")
local singer_col = string.match(str, "^singer%d$")
local length_col = string.match(str, "^length%d$")
local idx = string.match(str, "%d")
col = title_col or singer_col or length_col
if col and idx then
return {
['col'] = col,
['idx'] = idx
}
end
return nil
end
function p.main(frame)
local x = ''
local args = getArgs(frame)
local rows = {}
local root = mw.html.create()
for k,v in pairs(args) do
local col_idx = extract(k)
x = x .. ',' .. mw.text.jsonEncode(col_idx)
if col_idx then
local col = col_idx['col']
local idx = col_idx['idx']
-- rows[idx][col] = v
end
end
local root_table = root:tag('table')
:addClass('wikitable')
:css({
['margin-bottom'] = 0
})
:tag('tr')
:tag('th'):wikitext('No.'):done()
:tag('th'):wikitext('Title'):done()
:tag('th'):wikitext('Singer(s)'):done()
:tag('th'):wikitext('Length'):done()
:done()
for k,v in pairs(rows) do
local no = k
local title = v['title']
local singer = v['singer']
local length = v['length']
root_table:tag('tr')
:tag('th'):wikitext('1'):done()
:tag('td'):wikitext(title):done()
:tag('td'):wikitext(singer):done()
:tag('td')
:css({
['text-align'] = 'center'
})
:wikitext(length)
:done()
end
root_table:tag('tr')
:tag('th')
:attr('colspan', 3)
:css({
['text-align'] = 'right'
})
:wikitext('Total length:')
:done()
:tag('th')
:wikitext()
:done()
root:tag('sup')
:wikitext('[[Template:Track List|View]] • [[Template talk:Track List|Talk]]')
:done()
:done()
return tostring(root) .. x
end
return p