Module:Infobox

Revision as of 01:26, 3 August 2023 by PanchamBro (talk | contribs)

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

local p = {}

function p.main(frame)
    local c1, c2, title
        c1 = mw.text.trim(frame.args["color"] or "#ff8100")
        c2 = mw.text.trim(frame.args["text"] or "#000")
        title = frame.args["title"]
    local items = frame.args[1]
    if items ~= nil then
        items = mw.text.split(items, "\n")
    else
        items = {}
    end
    local result = {}
    table.insert(result, '<templatestyles src="Module:Infobox/styles.css"/><div class="infobox" style="border-color: '.. c1 ..'"><div class="infobox-title" style="background:'.. c1 ..'; color: '.. c2 ..'; grid-column: span 4; font-weight: normal; font-size: 1.5em; text-align:center; padding: .25rem; border-radius: .25rem;">'.. title ..'</div> ')
    local i = 1
    local x = 1
    local y = 2
    local item = {}
    local parents = {}
    local resultItems = ""
    local resultSection = ""
    local resultForm = ""
    while items[i] do
        item = mw.text.split(items[i], "//")
        if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then
            x = 1
            resultItems = ""
            while parents[x] do
                resultItems = resultItems .. parents[x]
                x = x + 1
            end
            y = 2
            resultSection = mw.text.trim(item[1])
            resultForm = item[2] or "N/A"
            resultExt = mw.text.trim(item[3] or "split")
            
            if resultExt == "label" or resultExt == "Label" then
                table.insert(result, '<div class="infobox-head infobox-'.. resultExt ..'" style="background:'.. c1 ..'; color:'.. c2 ..'; padding: .25rem">'.. resultSection ..'</div>')
            elseif resultExt == "expanded" or resultExt == "collapsed" then
                table.insert(result, '<div class="infobox-head infobox-wide mw-collapsible mw-'.. resultExt ..'" style="background:'.. c1 ..'; color:'.. c2 ..'; padding: .25rem">'.. resultSection ..'<div class="infobox-cell infobox-collapsible mw-collapsible-content style="padding: .25rem">'.. resultForm ..'</div></div>')
            else
                table.insert(result, '<div class="infobox-head infobox-'.. resultExt ..'" style="background:'.. c1 ..'; color:'.. c2 ..'; padding: .25rem">'.. resultSection ..'</div><div class="infobox-cell infobox-'.. resultExt ..'" style="padding: .25rem">'.. resultForm ..'</div>')
            end
        end
        i = i + 1
    end
    table.insert(result, "</div>")
    return table.concat(result, "")
end

return p