Module:KnownRecordings: Difference between revisions

From Weezerpedia
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 = {}
     local index = 1  -- Start with the first row
      
 
    -- Iterate through each row and gather the data
     -- Dynamically generate rows until no more data is found
     local index = 1
     while args["title" .. index] or args["performers" .. index] do
     while args["Performer" .. index] do
         local performers = args["performers" .. index] or ""
        -- Extract the values for each row
         local title = args["title" .. index] or ""
         local performer = args["Performer" .. index] or ""
         local filename = args["filename" .. index] or ""
         local title = args["Title" .. index] or ""
         local date = args["date" .. index] or ""
         local filename = args["Filename" .. index] or ""
         local location = args["location" .. index] or ""
         local date = args["Date" .. index] or ""
         local length = args["length" .. index] or ""
         local location = args["Location" .. index] or ""
         local appearedOn = args["appearedOn" .. index] or ""
         local length = args["Length" .. index] or ""
         local notes = args["notes" .. index] or ""
         local appearedOn = args["AppearedOn" .. index] or ""
         local status = args["status" .. index] or "unknown"
         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"]
          
          
         -- Wrap filename with <samp> for monospace display
         -- 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 with background color and no-wrap for the filename column
         -- 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 "",
             performers, title, filenameFormatted, date, location, length, appearedOn, notes
             performer, title, filenameFormatted, date, location, length, appearedOn, notes
         )
         )
         table.insert(rows, row)
         table.insert(rows, row)
          
          
         index = index + 1  -- Move to the next row
         -- Move to the next row
        index = index + 1
     end
     end


     -- Create table header (move the static part out to be clearer)
     -- Table header (static part)
     local header = [[
     local header = [[
         <tr>
         <tr>
Line 72: Line 76:
     )
     )


     -- Combine header, caption, and rows into a styled table
     -- 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