Module:KnownRecordings: Difference between revisions
No edit summary |
No edit summary Tag: Reverted |
||
Line 14: | Line 14: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local rows = {} | local rows = {} | ||
-- Iterate through each row and gather the data | |||
local index = 1 | |||
while args[" | while args["Performer" .. index] do | ||
local | -- Extract the values for each row | ||
local title = args[" | local performer = args["Performer" .. index] or "" | ||
local filename = args[" | local title = args["Title" .. index] or "" | ||
local date = args[" | local filename = args["Filename" .. index] or "" | ||
local location = args[" | local date = args["Date" .. index] or "" | ||
local length = args[" | local location = args["Location" .. index] or "" | ||
local appearedOn = args[" | local length = args["Length" .. index] or "" | ||
local notes = args[" | local appearedOn = args["AppearedOn" .. index] or "" | ||
local status = args[" | local notes = args["Notes" .. index] or "" | ||
local status = args["Status" .. index] or "unknown" | |||
-- Determine the background color for the row based on the status | |||
local color = statusColors[status:lower()] or statusColors["unknown"] | local color = statusColors[status:lower()] or statusColors["unknown"] | ||
-- | -- Format filename with <samp> for monospace | ||
local filenameFormatted = string.format('<samp>%s</samp>', filename) | local filenameFormatted = string.format('<samp>%s</samp>', filename) | ||
-- Create table row | -- Create the table row | ||
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 "", | ||
performer, title, filenameFormatted, date, location, length, appearedOn, notes | |||
) | ) | ||
table.insert(rows, row) | table.insert(rows, row) | ||
-- Move to the next row | |||
index = index + 1 | |||
end | end | ||
-- | -- Table header (static part) | ||
local header = [[ | local header = [[ | ||
<tr> | <tr> | ||
Line 72: | Line 76: | ||
) | ) | ||
-- Combine header, | -- Combine the table header, rows, and caption | ||
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 12:26, 27 November 2024
Documentation for this module may be created at Module:KnownRecordings/doc
local p = {}
-- Define the color map based on the status
local statusColors = {
released = "#aaffaa",
unreleased = "#ffaaaa",
["partially released"] = "#ffffaa",
duplicate = "#cccccc",
unknown = nil
}
-- Main function to render the table
function p.renderTable(frame)
local args = frame:getParent().args
local rows = {}
-- Iterate through each row and gather the data
local index = 1
while args["Performer" .. index] do
-- Extract the values for each row
local performer = args["Performer" .. index] or ""
local title = args["Title" .. index] or ""
local filename = args["Filename" .. index] or ""
local date = args["Date" .. index] or ""
local location = args["Location" .. index] or ""
local length = args["Length" .. index] or ""
local appearedOn = args["AppearedOn" .. index] or ""
local notes = args["Notes" .. index] or ""
local status = args["Status" .. index] or "unknown"
-- Determine the background color for the row based on the status
local color = statusColors[status:lower()] or statusColors["unknown"]
-- Format filename with <samp> for monospace
local filenameFormatted = string.format('<samp>%s</samp>', filename)
-- Create the table row
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 "",
performer, title, filenameFormatted, date, location, length, appearedOn, notes
)
table.insert(rows, row)
-- Move to the next row
index = index + 1
end
-- Table header (static part)
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>
]]
-- Create a small MediaWiki link for the caption
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' .. ']]'
)
)
)
-- Combine the table header, rows, and caption
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