Module:KnownRecordings: Difference between revisions
Tag: Undo |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local statusColors = { | local statusColors = { | ||
released = "#aaffaa", | released = "#aaffaa", | ||
unreleased = "#ffaaaa", | unreleased = "#ffaaaa", | ||
["partially released"] = "#ffffaa", | ["partially released"] = "#ffffaa", | ||
duplicate = "#cccccc", | duplicate = "#cccccc", | ||
unknown = nil | unknown = nil | ||
} | } | ||
function p.renderTable(frame) | function p.renderTable(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local rows = {} | local rows = {} | ||
local index = 1 | local index = 1 | ||
while args[index] do | while args[index] do | ||
local rowData = {} | local rowData = {} | ||
local rowString = args[index] | local rowString = args[index] | ||
-- Split the | -- Split the row into fields | ||
for field in rowString:gmatch("([^|]+)") do | for field in rowString:gmatch("([^|]+)") do | ||
table.insert(rowData, field) | table.insert(rowData, field) | ||
end | end | ||
while #rowData < 8 do | while #rowData < 8 do | ||
table.insert(rowData, "") | table.insert(rowData, "") | ||
end | end | ||
local performers = mw.text.encode(rowData[1] or "") | |||
local performers = rowData[1] or "" | local title = mw.text.encode(rowData[2] or "") | ||
local title = rowData[2] or "" | local filename = mw.text.encode(rowData[3] or "") | ||
local filename = rowData[3] or "" | local date = mw.text.encode(rowData[4] or "") | ||
local date = rowData[4] or "" | local location = mw.text.encode(rowData[5] or "") | ||
local location = rowData[5] or "" | local length = mw.text.encode(rowData[6] or "") | ||
local length = rowData[6] or "" | local appearedOn = mw.text.encode(rowData[7] or "") | ||
local appearedOn = rowData[7] or "" | local notes = mw.text.encode(rowData[8] or "") | ||
local notes = rowData[8] or "" | |||
local status = rowData[#rowData] or "unknown" | local status = rowData[#rowData] or "unknown" | ||
local color = statusColors[status:lower()] or statusColors["unknown"] | local color = statusColors[status:lower()] or statusColors["unknown"] | ||
local filenameFormatted = string.format('<samp>%s</samp>', filename) | local filenameFormatted = string.format('<samp>%s</samp>', filename) | ||
local row = string.format( | local row = string.format( | ||
'<tr%s><td>%s</td><td>%s</td><td style="white-space: nowrap;">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', | '<tr%s><td>%s</td><td>%s</td><td style="white-space: nowrap;">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', | ||
color and (' style="background-color:' .. color .. ';"') or "", | color and (' style="background-color:' .. color .. ';"') or "", | ||
performers, title, filenameFormatted, date, location, length, appearedOn, notes | performers, title, filenameFormatted, date, location, length, appearedOn, notes | ||
) | ) | ||
table.insert(rows, row) | table.insert(rows, row) | ||
index = index + 1 | index = index + 1 | ||
end | end | ||
local header = [[ | local header = [[ | ||
<tr> | <tr> | ||
Line 73: | Line 63: | ||
]] | ]] | ||
local caption = mw.text.tag( | local caption = mw.text.tag( | ||
'caption', | 'caption', | ||
Line 88: | Line 77: | ||
) | ) | ||
return string.format( | return string.format( | ||
'<table class="wikitable" style="margin:0.5em; font-size:.8em;">%s%s%s</table>', | '<table class="wikitable" style="margin:0.5em; font-size:.8em;">%s%s%s</table>', |
Revision as of 13:01, 27 November 2024
Documentation for this module may be created at Module:KnownRecordings/doc
local p = {}
local statusColors = {
released = "#aaffaa",
unreleased = "#ffaaaa",
["partially released"] = "#ffffaa",
duplicate = "#cccccc",
unknown = nil
}
function p.renderTable(frame)
local args = frame:getParent().args
local rows = {}
local index = 1
while args[index] do
local rowData = {}
local rowString = args[index]
-- Split the row into fields
for field in rowString:gmatch("([^|]+)") do
table.insert(rowData, field)
end
while #rowData < 8 do
table.insert(rowData, "")
end
local performers = mw.text.encode(rowData[1] or "")
local title = mw.text.encode(rowData[2] or "")
local filename = mw.text.encode(rowData[3] or "")
local date = mw.text.encode(rowData[4] or "")
local location = mw.text.encode(rowData[5] or "")
local length = mw.text.encode(rowData[6] or "")
local appearedOn = mw.text.encode(rowData[7] or "")
local notes = mw.text.encode(rowData[8] or "")
local status = rowData[#rowData] or "unknown"
local color = statusColors[status:lower()] or statusColors["unknown"]
local filenameFormatted = string.format('<samp>%s</samp>', filename)
local row = string.format(
'<tr%s><td>%s</td><td>%s</td><td style="white-space: nowrap;">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
color and (' style="background-color:' .. color .. ';"') or "",
performers, title, filenameFormatted, date, location, length, appearedOn, notes
)
table.insert(rows, row)
index = index + 1
end
local header = [[
<tr>
<th>Performer(s)</th>
<th>Title</th>
<th>Filename</th>
<th>Date of recording</th>
<th>Recording location</th>
<th>Length</th>
<th>Appeared on</th>
<th>Notes</th>
</tr>
]]
local caption = mw.text.tag(
'caption',
{ style = 'caption-side: bottom; text-align: right;' },
mw.text.tag(
'small',
nil,
mw.text.tag(
'i',
nil,
'[[' .. 'Weezerpedia:Known recordings|about this table' .. ']]'
)
)
)
return string.format(
'<table class="wikitable" style="margin:0.5em; font-size:.8em;">%s%s%s</table>',
caption,
header,
table.concat(rows)
)
end
return p