Module:KnownRecordings: Difference between revisions
Tag: Undo |
No edit summary Tag: Reverted |
||
Line 33: | Line 33: | ||
-- Extract other fields (same order as column headers) | -- Extract other fields (same order as column headers) | ||
local performers = mw.text.encode(rowData[1] or "") | |||
local title = rowData[2] or "" | local title = mw.text.encode(rowData[2] or "") | ||
local filename = rowData[3] or "" | local filename = mw.text.encode(rowData[3] or "") | ||
local date = rowData[4] or "" | local date = mw.text.encode(rowData[4] or "") | ||
local location = rowData[5] or "" | local location = mw.text.encode(rowData[5] or "") | ||
local length = rowData[6] or "" | local length = mw.text.encode(rowData[6] or "") | ||
local appearedOn = rowData[7] or "" | local appearedOn = mw.text.encode(rowData[7] or "") | ||
local notes = rowData[8] or "" | local notes = mw.text.encode(rowData[8] or "") | ||
-- Extract the status from the last column (assumed to be the last value) | -- Extract the status from the last column (assumed to be the last value) |
Revision as of 13:03, 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", -- Green
unreleased = "#ffaaaa", -- Red
["partially released"] = "#ffffaa", -- Yellow
duplicate = "#cccccc", -- Grey
unknown = nil -- No color (no background)
}
-- Main function to render the table
function p.renderTable(frame)
local args = frame:getParent().args
local rows = {}
local index = 1 -- Start with the first row
-- Dynamically generate rows until no more data is found
while args[index] do
-- Split the row into fields based on '|'
local rowData = {}
local rowString = args[index]
-- Split the string by '|' into separate fields
for field in rowString:gmatch("([^|]+)") do
table.insert(rowData, field)
end
-- Ensure there are enough columns (add default values if necessary)
while #rowData < 8 do
table.insert(rowData, "")
end
-- Extract other fields (same order as column headers)
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 "")
-- Extract the status from the last column (assumed to be the last value)
local status = rowData[#rowData] or "unknown"
local color = statusColors[status:lower()] or statusColors["unknown"]
-- Wrap filename with <samp> for monospace display
local filenameFormatted = string.format('<samp>%s</samp>', filename)
-- Create table row with background color and no-wrap for the filename column
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 "", -- Apply background color if it exists
performers, title, filenameFormatted, date, location, length, appearedOn, notes
)
table.insert(rows, row)
index = index + 1 -- Move to the next row
end
-- Create table header
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>
]]
-- Add caption below the table using MediaWiki-compatible syntax
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 header, caption, and rows into a styled 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