Module:BDVol

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:BDVol/doc

local p = {}

local getArgs = require('Module:Arguments').getArgs

function p.renderVolumeTable(frame)
    local args = getArgs(frame)
    local title = args.Title or ""
    local vol = args.Vol or ""
    local part = args.Part or "PB"
    local jpTitle = args.JPTitle or ""
    local icon = args.Icon or part .. "IconAnime"
    local cover = args.Cover or ""
    local cover2 = args.Cover2 or ""
    local cover3 = args.Cover3 or ""
    local cover4 = args.Cover4 or ""
    local date = args.Date or "TBA"
    local price = args.Price or ""
    local discs = args.Discs or "1"
    local episodes = args.Episodes or ""
    local barcode = args.Barcode or ""
    local specs = args.Specs or ""
    local leBonus = args.LEBonus or ""
    local total = tonumber(args.Total) or 0
    local start = tonumber(args.Start) or 1
    local noNumbers = args.NoNumbers or ""

    local output = {}

    local function expandColor(partSuffix)
        if part == "PBBT" then
            return frame:expandTemplate{ title = 'Color', args = { "PB" .. partSuffix } }
        else
            return frame:expandTemplate{ title = 'Color', args = { part .. partSuffix } }
        end
    end

    -- Include CSS styles
    table.insert(output, '<div id="' .. title .. '" class="volumeTable volume">')

    -- Volume table top
    table.insert(output, '<div class="volumeTableTop"><div class="volumeTableHead">')
    if vol ~= "" then
        local volColor = expandColor("3")
        table.insert(output, '<div class="diamond volumeTableNumber volumeTableNumberBD' .. (title == "" and " noTitle" or "") .. '" style="background-color:' .. volColor .. ';">' .. vol .. '</div>')
    end

    local titleClass = "diamond volumeTableTitle volumeTableTitle2"
    if part == "PBBT" then
        titleClass = titleClass .. " PBBTTitle"
    end

    local titleColor = expandColor("")
    table.insert(output, '<div class="' .. titleClass .. '" style="background-color:' .. titleColor .. ';">')
    table.insert(output, title)
    if jpTitle ~= "" then
        table.insert(output, '<br />' .. frame:expandTemplate{ title = 'S', args = { frame:expandTemplate{ title = 'Nihongo', args = { jpTitle, type1 = 'J' } } } })
    end
    if title ~= "" then
        local iconSize = (part == "PB" or part == "PBBT") and "16px" or "25px"
        table.insert(output, '<span class="boxAnchorLink">[[File:' .. icon .. '.png|' .. iconSize .. '|link=#Volume ' .. vol .. '|Link to this section]]</span>')
    end
    table.insert(output, '</div></div></div>')

    -- Volume table bottom
    table.insert(output, '<div class="volumeTableBottom">')
    if cover ~= "" then
        local coverColor = expandColor("4")
        local iWidth = args.IWidth or "150px"
        table.insert(output, '<div class="volumeTableImage diamond" style="background-color:' .. coverColor .. '; min-width:' .. iWidth .. ';">')
        if cover2 ~= "" or cover3 ~= "" or cover4 ~= "" then
            local tabberArgs = {}
            table.insert(tabberArgs, (args.CoverN or 'BD'))
            table.insert(tabberArgs, cover)
            if cover2 ~= "" then
                table.insert(tabberArgs, (args.Cover2N or 'DVD'))
                table.insert(tabberArgs, cover2)
            end
            if cover3 ~= "" then
                table.insert(tabberArgs, (args.Cover3N or 'Set'))
                table.insert(tabberArgs, cover3)
            end
            if cover4 ~= "" then
                table.insert(tabberArgs, (args.Cover4N or '4th'))
                table.insert(tabberArgs, cover4)
            end
            table.insert(output, frame:expandTemplate{ title = 'tabber', args = tabberArgs })
        else
            table.insert(output, cover)
        end
        table.insert(output, '</div>')
    end

    table.insert(output, '<div class="' .. (cover ~= "" and "volumeTableAllChapters" or "volumeTableAllChapters2") .. '">')
    table.insert(output, '<div class="volumeTableInfo"><div class="volumeTableBDRow"><div class="volumeTableBDDateContainer">')
    table.insert(output, '<div class="volumeTableHeading volumeTableCell volumeTableBDDateHeading" style="background-color:' .. expandColor("2") .. ';">')
    table.insert(output, "'''Release Date'''</div>")
    table.insert(output, '<div class="volumeTableCell volumeTableBDDate">' .. frame:expandTemplate{ title = 'Flag', args = { args.Flag or 'Japan' } } .. ' ' .. date .. '</div></div>')
    if price ~= "" then
        table.insert(output, '<div class="volumeTableBDPriceContainer"><div class="volumeTableHeading volumeTableCell volumeTableBDPriceHeading" style="background-color:' .. expandColor("2") .. ';">')
        table.insert(output, "'''Price'''</div>")
        table.insert(output, '<div class="volumeTableCell volumeTableBDPrice">' .. price .. '</div></div>')
    end
    if discs ~= "" then
        table.insert(output, '<div class="volumeTableBDDiscContainer"><div class="volumeTableHeading volumeTableCell volumeTableBDDiscHeading" style="background-color:' .. expandColor("2") .. ';">')
        table.insert(output, "'''Discs'''</div>")
        table.insert(output, '<div class="volumeTableCell volumeTableBDDisc">' .. discs .. '</div></div>')
    end
    if episodes ~= "" then
        table.insert(output, '<div class="volumeTableBDEpsContainer"><div class="volumeTableHeading volumeTableCell volumeTableBDEpsHeading" style="background-color:' .. expandColor("2") .. ';">')
        table.insert(output, "'''Episodes'''</div>")
        table.insert(output, '<div class="volumeTableCell volumeTableBDEps">' .. episodes .. '</div></div>')
    end
    table.insert(output, '</div>')
    if barcode ~= "" then
        table.insert(output, '<div class="volumeTableBDRow"><div class="volumeTableHeading volumeTableCell volumeTableBDBarcodeHeading" style="background-color:' .. expandColor("2") .. ';">')
        table.insert(output, "'''Barcode'''</div>")
        table.insert(output, '<div class="volumeTableCell volumeTableBDBarcode">' .. barcode .. '</div></div>')
    end
    table.insert(output, '</div>')

    if specs ~= "" or leBonus ~= "" or args["E1-1"] ~= "" then
        table.insert(output, '<div class="volumeTableBDContainer" style="display: flex;">')
    end

    -- Specifications
    if specs ~= "" or leBonus ~= "" then
        table.insert(output, '<div class="volumeTableBDColumn">')
        table.insert(output, '<div class="volumeTableBDColumnHeader" style="background-color:' .. expandColor("3") .. ';">Specifications</div>')
        table.insert(output, '<div class="volumeTableChList volumeTableSpecifications">'
        .. (specs ~= "" and "'''Features: ''' " .. specs or "")
        .. (leBonus ~= "" and "<br /><div class='volumeTableBonuses'>'''"
        .. (args.BonusText or 'Limited Edition Bonuses') .. "''': " .. leBonus .. '</div>' or "")
        .. '</div></div>')
        table.insert(output, '</div>') -- End of volumeTableBDColumn for Specifications
    end

    -- Episode list
    if total > 0 then
        table.insert(output, '<div class="volumeTableBDColumn">')
        table.insert(output, '<div class="volumeTableBDColumnHeader" style="background-color:' .. expandColor("3") .. ';">Episode List</div>')
        local episodesList = {}
        table.insert(episodesList, '<div class="volumeTableChList volumeTableScroll2">')
        if noNumbers == "True" then
            table.insert(episodesList, '<ul>')
        else
            table.insert(episodesList, '<ol start="' .. start .. '">')
        end
        for i = 1, total do
            local episode = args["E1-" .. i] or ""
            if episode ~= "" then
                table.insert(episodesList, '<li>' .. episode .. '</li>')
            end
        end
        if noNumbers == "True" then
            table.insert(episodesList, '</ul>')
        else
            table.insert(episodesList, '</ol>')
        end
        table.insert(episodesList, '</div>')
        table.insert(output, table.concat(episodesList))
        table.insert(output, '</div>') -- End of volumeTableBDColumn for Episode List
    end

    if specs ~= "" or leBonus ~= "" or args["E1-1"] ~= "" then
        table.insert(output, '</div>') -- End of volumeTableBDContainer
    end

    table.insert(output, '</div></div></div></div>')

    return table.concat(output)
end

return p