Přeskočit na obsah

Modul:Box barvy

Z Infopedia

Dokumentaci tohoto modulu lze vytvořit na stránce Modul:Box barvy/Dokumentace

local p = {}

function p.main(frame)
    local args = frame:getParent() and frame:getParent().args or frame.args
    -- Pokud je šablona volaná přímo z jiného modulu, použij frame.args jako fallback
    if frame:getParent() then
        args = frame:getParent().args
    else
        args = frame.args
    end

    local size = args['velikost'] or '12px'
    local shape = args['tvar'] or 'čtverec' -- 'čtverec' nebo 'kolečko'
    local borderRadius = ''
    if shape == 'kolečko' or shape == 'kruh' then
        borderRadius = 'border-radius:50%;'
    end

    local result = {}
    local i = 1
    while args[tostring(i)] and args[tostring(i)] ~= '' do
        local color = args[tostring(i)]
        table.insert(result, string.format(
            '<span style="display:inline-block;width:%s;height:%s;background-color:%s;border:1px solid #888;margin-right:2px;vertical-align:middle;%s"></span>',
            size, size, color, borderRadius
        ))
        i = i + 1
    end

    if #result == 0 then
        return ''
    end

    return '<span style="white-space:nowrap;">' .. table.concat(result) .. '</span>'
end

return p