Module:KnownRecordings: Difference between revisions
m (Admin moved page Module:SongRecordingTable to Module:KnownRecordings without leaving a redirect) |
No edit summary Tag: Reverted |
||
Line 14: | Line 14: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local rows = {} | local rows = {} | ||
-- | -- Iterate over the rows, each containing a set of data for a single row in the table | ||
local data = args[1] or "" | |||
local | local rowData = {} | ||
local title = | |||
local filename = | -- Split the input data by pipe separator to get each row's data | ||
local date = | for entry in string.gmatch(data, "([^|]+)") do | ||
local location = | table.insert(rowData, entry) | ||
local length = | end | ||
local | |||
local notes = | -- Determine how many rows there are based on the number of columns (9 in this case) | ||
local status = | local numRows = math.floor(#rowData / 9) | ||
for i = 0, numRows - 1 do | |||
-- Each row will have 9 elements (artist, title, filename, date, location, length, album, notes, status) | |||
local startIdx = i * 9 + 1 | |||
local row = {} | |||
for j = 0, 8 do | |||
table.insert(row, rowData[startIdx + j]) | |||
end | |||
-- Extract row fields | |||
local artist = row[1] | |||
local title = row[2] | |||
local filename = row[3] | |||
local date = row[4] | |||
local location = row[5] | |||
local length = row[6] | |||
local album = row[7] | |||
local notes = row[8] | |||
local status = row[9] or "unknown" | |||
-- Determine the background color based on the status | |||
local color = statusColors[status:lower()] or statusColors["unknown"] | local color = statusColors[status:lower()] or statusColors["unknown"] | ||
-- Create table row with background color and no-wrap for filename | |||
local rowHTML = string.format( | |||
'<tr%s><td>%s</td><td>%s</td><td><samp>%s</samp></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', | |||
-- Create table row with background color and no-wrap for | |||
local | |||
'<tr%s><td>%s</td><td>%s</td><td | |||
color and (' style="background-color:' .. color .. ';"') or "", | color and (' style="background-color:' .. color .. ';"') or "", | ||
artist, title, filename, date, location, length, album, notes | |||
) | ) | ||
table.insert(rows, | table.insert(rows, rowHTML) | ||
end | end | ||
-- | -- Combine all rows into a table | ||
local | local tableHTML = string.format('<table class="wikitable" style="margin:0.5em; font-size:.8em; border:1px solid #aaa; width:100%%;">%s</table>', table.concat(rows)) | ||
-- Use the correct MediaWiki caption markup without extra single quotes | |||
local captionHTML = '|+style="caption-side:top; text-align:left;"|<small><i>[[Weezerpedia:Known recordings|about this table]]</i></small>' | |||
-- | |||
local | |||
-- | -- Return the table with the caption | ||
return | return tableHTML .. captionHTML | ||
end | end | ||
return p | return p |
Revision as of 12:08, 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 over the rows, each containing a set of data for a single row in the table
local data = args[1] or ""
local rowData = {}
-- Split the input data by pipe separator to get each row's data
for entry in string.gmatch(data, "([^|]+)") do
table.insert(rowData, entry)
end
-- Determine how many rows there are based on the number of columns (9 in this case)
local numRows = math.floor(#rowData / 9)
for i = 0, numRows - 1 do
-- Each row will have 9 elements (artist, title, filename, date, location, length, album, notes, status)
local startIdx = i * 9 + 1
local row = {}
for j = 0, 8 do
table.insert(row, rowData[startIdx + j])
end
-- Extract row fields
local artist = row[1]
local title = row[2]
local filename = row[3]
local date = row[4]
local location = row[5]
local length = row[6]
local album = row[7]
local notes = row[8]
local status = row[9] or "unknown"
-- Determine the background color based on the status
local color = statusColors[status:lower()] or statusColors["unknown"]
-- Create table row with background color and no-wrap for filename
local rowHTML = string.format(
'<tr%s><td>%s</td><td>%s</td><td><samp>%s</samp></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
color and (' style="background-color:' .. color .. ';"') or "",
artist, title, filename, date, location, length, album, notes
)
table.insert(rows, rowHTML)
end
-- Combine all rows into a table
local tableHTML = string.format('<table class="wikitable" style="margin:0.5em; font-size:.8em; border:1px solid #aaa; width:100%%;">%s</table>', table.concat(rows))
-- Use the correct MediaWiki caption markup without extra single quotes
local captionHTML = '|+style="caption-side:top; text-align:left;"|<small><i>[[Weezerpedia:Known recordings|about this table]]</i></small>'
-- Return the table with the caption
return tableHTML .. captionHTML
end
return p