Module:InfoboxProperty

From Inkipedia, the Splatoon wiki

Produces a labeled property for an infobox. The markup produced represents a two-column table row.

Parameters

name Unnamed. The contents of the property's name cell.
value Unnamed. The contents of the property's value cell.
color Optional. An RGB triplet to use as the base color for formatting. The default color is 0, 153, 255, defined in SiteColor as "Generic".
style Optional. A CSS property list to apply to the property's value cell.

Example

Markup

{{Infobox/Property|color={{SiteColor|Splatoon}}|Name|Value}}
{{Infobox/Property|color=something else|Name 2|Value 2}}
{{Infobox/Property|Name 3|Value 3}}

Output

Name Value
Name 2 Value 2
Name 3 Value 3

local p = {}
local siteColorModule = require("Module:SiteColor")

function p.getRow(name, value, color, style)
    -- If the value is empty, add a "display:none" style
    local rowStyle = ""
    if value == "" then
    	rowStyle = "style=\"display: none;\""
    end

    local rowTable = {}

    -- Add the first cell, with styling for color and gradient
    local firstCellStyleParts = {
        "|- ", rowStyle,
        "\n|style=\"padding: 5px; ",
        "background: linear-gradient(to right, rgba(", color, ", 0.3) 0%, rgba(", color, ", 0) 100%); ",
        "border-width: 1px 0px 1px 5px; border-style: solid; ",
        "border-color: rgba(", color, ", 0.5); border-radius: 5px 0px 0px 5px;\"",
        "|'''", name, "'''"
    }

    table.insert(rowTable, table.concat(firstCellStyleParts))

    -- Add the second cell
    table.insert(rowTable, table.concat({"|style=\"", style, "\"|", value}))

    return table.concat(rowTable, "\n")
end

function p.main(frame)
    local args = frame:getParent().args
    
    -- Pull out the args from the frame and pass to getRow
    local color = args["color"] or siteColorModule.getSiteColor("Generic")
    local name = args[1] or ""
    local value = args[2] or ""
    local style = args["style"] or ""

    return p.getRow(name, value, color, style)
end

return p