Jump to content
Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

La documentation pour ce module peut être créée à Module:Configurations/doc

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local titre = args['titre']
    if not titre or titre == '' then
        titre = 'Configurations disponibles'
    end

    local columns = {
        { key = 'processeur', label = 'Processeur' },
        { key = 'ram', label = 'Mémoire' },
        { key = 'stockage', label = 'Stockage' },
        { key = 'écran', label = 'Écran' },
        { key = 'graphics', label = 'Carte graphique' },
        { key = 'autres', label = 'Autres' },
    }

    local rows = {}
    local i = 1
    while true do
        local variante = args['variante' .. i]
        if not variante or variante == '' then
            break
        end
        local row = { variante = variante }
        for _, col in ipairs(columns) do
            row[col.key] = args[col.key .. i] or ''
        end
        table.insert(rows, row)
        i = i + 1
    end

    if #rows == 0 then
        return ''
    end

    local usedColumns = {}
    for _, col in ipairs(columns) do
        for _, row in ipairs(rows) do
            if row[col.key] ~= '' then
                table.insert(usedColumns, col)
                break
            end
        end
    end

    local header = '! Variante'
    for _, col in ipairs(usedColumns) do
        header = header .. ' !! ' .. col.label
    end

    local body = {}
    for _, row in ipairs(rows) do
        local line = "|-\n|\n'''" .. row.variante .. "'''\n"
        for _, col in ipairs(usedColumns) do
            line = line .. '|\n' .. row[col.key] .. '\n'
        end
        table.insert(body, line)
    end

    local out = '<div class="ith-config-wrap">\n'
        .. '{| class="wikitable sortable mw-collapsible ith-config-table"\n'
        .. '|+ ' .. titre .. '\n'
        .. header .. '\n'
        .. table.concat(body)
        .. '|}\n'
        .. '</div>'

    return out
end

return p