モジュール:Userbox lang

提供:人工言語学Wiki

このモジュールについての説明文ページを モジュール:Userbox lang/doc に作成できます

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

local p = {}

local params = {
    ["0"] = {
        border = "#FFB3B3",
        icon = "#FFB3B3",
        bg = "#FFE0E8",
    },
    ["1"] = {
        border = "#c0c8ff",
        icon = "#c0c8ff",
        bg = "#f0f8ff",
    },
    ["2"] = {
        border = "#77e0e8",
        icon = "#77e0e8",
        bg = "#d0f8ff",
    },
    ["3"] = {
        border = "#99b3ff",
        icon = "#99b3ff",
        bg = "#e0e8ff",
    },
    ["4"] = {
        border = "#cccc01",
        icon = "#ffff00",
        bg = "#ffff99",
    },
    ["5"] = {
        border = "#F99C99",
        icon = "#DF6060",
        bg = "#FF8080",
    },
    N = {
        border = "#6EF7A7",
        icon = "#6EF7A7",
        bg = "#c5fcdc",
    },
    C = {
        border = "#ffe1b5",
        icon = "#ffe1b5",
        bg = "#fff0de",
    },
}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args, frame)
end

function p._main(args, frame)
    local function take_text(table, key)
        local value = table[key]
        if value then
            return value
        else
            return ""
        end
    end

    local icon = args["icon"]
    local showIcon = icon and true or false
    local name = args["name"]
    if not name then
        name = "lang"
    end

    local level = args["level"]
    if not level then
        return ""
    end

    local param = params[level]
    if not param then
        return ""
    end

    local expand = ""

    local id = name .. "-" .. level
    if level == "N" then
        id = name
    end

    if not showIcon then
        local templateArgs = {
            ["id-s"] = 14,
            ["info-s"] = 9,
            ["info"] = take_text(args, "text-" .. level),
            ["id"] = id,
            ["border-c"] = param.border,
            ["id-c"] = param.icon,
            ["info-c"] = param.bg,
        }
        expand = frame:expandTemplate{
            title = "Userbox",
            args = templateArgs
        }
    else
        local templateArgs = {
            ["id-s"] = 14,
            ["info-s"] = 9,
            ["info"] = take_text(args, "text-" .. level),
            ["id1"] = id,
            ["id2"] = "[[File:" .. icon .. "|44px]]",
            ["border-c"] = param.border,
            ["id1-c"] = param.icon,
            ["id2-c"] = param.icon,
            ["info-c"] = param.bg,
        }
        expand = frame:expandTemplate{
            title = "Userbox-2",
            args = templateArgs
        }
    end

    return expand
end

return p