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.

« Module:TableColors » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
mAucun résumé des modifications
Hiob (discussion | contributions)
Parsed frame:preprocess()
Ligne 34 : Ligne 34 :
}
}


-- Fonction principale
-- Fonction principale pour styliser une cellule
function p.style(frame)
function p.style(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local colorName = mw.text.trim(args[1] or ""):lower()
     local colorName = mw.text.trim(args[1] or ""):lower()
     local content = args[2] -- Ne pas trim ici pour garder le formatage
     local content = args[2]
      
      
     -- Gestion des alias
     -- Gestion des alias
Ligne 55 : Ligne 55 :
     -- Construction du style
     -- Construction du style
     local style = string.format(
     local style = string.format(
         'background-color: %s; color: %s',
         'style="background-color: %s; color: %s"',
         color.bg,
         color.bg,
         color.fg
         color.fg
     )
     )
      
      
     -- Si pas de contenu ou contenu vide
     -- Si pas de contenu ou contenu vide/nil
     if not content or mw.text.trim(content) == "" then
     if not content then
         return 'style="' .. style .. '"'
         return style
     end
     end
      
      
     -- Si contenu présent
    local trimmedContent = mw.text.trim(content)
     return 'style="' .. style .. '" | ' .. content
    if trimmedContent == "" then
        return style
    end
   
     -- Si contenu présent, retourner avec séparateur
     return style .. ' | ' .. content
end
end


-- Fonction pour lister les couleurs disponibles
-- Fonction pour lister les couleurs disponibles
function p.list(frame)
function p.list(frame)
     local output = {}
     local rows = {}
    table.insert(output, '{| class="wikitable sortable"')
    table.insert(output, '! Nom !! Aperçu !! Code')
      
      
    -- Trier les noms de couleurs
     local sorted = {}
     local sorted = {}
     for name, _ in pairs(colors) do
     for name, _ in pairs(colors) do
Ligne 81 : Ligne 85 :
     table.sort(sorted)
     table.sort(sorted)
      
      
    -- Construire les lignes du tableau
     for _, name in ipairs(sorted) do
     for _, name in ipairs(sorted) do
         local color = colors[name]
         local color = colors[name]
         table.insert(output, '|-')
         local row = string.format(
        table.insert(output, string.format(
             '|-\n| %s || style="background:%s; color:%s; padding:8px 15px; font-weight:500;" | %s || <code>{{Couleur|%s}}</code>',
             '| %s || style="background:%s; color:%s; padding:8px 15px; font-weight:500;" | %s || <code>{{{{Couleur|%s}}}}</code>',
             color.label,
             color.label,
             color.bg,
             color.bg,
Ligne 91 : Ligne 95 :
             color.label,
             color.label,
             name
             name
         ))
         )
        table.insert(rows, row)
     end
     end
      
      
     table.insert(output, '|}')
     -- Assembler le tableau complet
    local wikitext = '{| class="wikitable sortable"\n! Nom !! Aperçu !! Code\n'
        .. table.concat(rows, '\n')
        .. '\n|}'
      
      
     return table.concat(output, '\n')
    -- Parser le wikitext avant de le retourner
     return frame:preprocess(wikitext)
end
end


return p
return p

Version du 3 octobre 2025 à 08:15

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

local p = {}

-- Palette inspirée de Bootstrap 5 + Citizen
local colors = {
    -- Variantes de succès (vert)
    success = { bg = "#d1e7dd", fg = "#0f5132", label = "Succès" },
    ["success-light"] = { bg = "#e8f5e9", fg = "#1b5e20", label = "Succès clair" },
    
    -- Variantes de danger (rouge)
    danger = { bg = "#f8d7da", fg = "#842029", label = "Danger" },
    ["danger-light"] = { bg = "#ffebee", fg = "#c62828", label = "Danger clair" },
    
    -- Variantes d'avertissement (jaune/orange)
    warning = { bg = "#fff3cd", fg = "#664d03", label = "Avertissement" },
    ["warning-light"] = { bg = "#fffde7", fg = "#f57f17", label = "Avertissement clair" },
    
    -- Variantes d'information (bleu)
    info = { bg = "#cfe2ff", fg = "#084298", label = "Info" },
    ["info-light"] = { bg = "#e3f2fd", fg = "#01579b", label = "Info clair" },
    
    -- Variantes neutres
    primary = { bg = "#cfe2ff", fg = "#052c65", label = "Primaire" },
    secondary = { bg = "#e2e3e5", fg = "#41464b", label = "Secondaire" },
    light = { bg = "#f8f9fa", fg = "#495057", label = "Clair" },
    dark = { bg = "#ced4da", fg = "#212529", label = "Foncé" },
    
    -- Compatibilité anciens noms
    vert = { bg = "#d1e7dd", fg = "#0f5132", label = "Vert" },
    rouge = { bg = "#f8d7da", fg = "#842029", label = "Rouge" },
    jaune = { bg = "#fff3cd", fg = "#664d03", label = "Jaune" },
    rose = { bg = "#f8d7da", fg = "#842029", label = "Rose" },
    gris = { bg = "#e2e3e5", fg = "#41464b", label = "Gris" },
    bleu = { bg = "#cfe2ff", fg = "#084298", label = "Bleu" },
}

-- Fonction principale pour styliser une cellule
function p.style(frame)
    local args = frame:getParent().args
    local colorName = mw.text.trim(args[1] or ""):lower()
    local content = args[2]
    
    -- Gestion des alias
    local aliases = {
        ["gris-"] = "info-light",
        ["gris+"] = "secondary",
        ["vert-clair"] = "success-light",
        ["rouge-clair"] = "danger-light",
    }
    
    colorName = aliases[colorName] or colorName
    
    -- Récupération de la couleur
    local color = colors[colorName] or colors.light
    
    -- Construction du style
    local style = string.format(
        'style="background-color: %s; color: %s"',
        color.bg,
        color.fg
    )
    
    -- Si pas de contenu ou contenu vide/nil
    if not content then
        return style
    end
    
    local trimmedContent = mw.text.trim(content)
    if trimmedContent == "" then
        return style
    end
    
    -- Si contenu présent, retourner avec séparateur
    return style .. ' | ' .. content
end

-- Fonction pour lister les couleurs disponibles
function p.list(frame)
    local rows = {}
    
    -- Trier les noms de couleurs
    local sorted = {}
    for name, _ in pairs(colors) do
        table.insert(sorted, name)
    end
    table.sort(sorted)
    
    -- Construire les lignes du tableau
    for _, name in ipairs(sorted) do
        local color = colors[name]
        local row = string.format(
            '|-\n| %s || style="background:%s; color:%s; padding:8px 15px; font-weight:500;" | %s || <code>{{Couleur|%s}}</code>',
            color.label,
            color.bg,
            color.fg,
            color.label,
            name
        )
        table.insert(rows, row)
    end
    
    -- Assembler le tableau complet
    local wikitext = '{| class="wikitable sortable"\n! Nom !! Aperçu !! Code\n' 
        .. table.concat(rows, '\n') 
        .. '\n|}'
    
    -- Parser le wikitext avant de le retourner
    return frame:preprocess(wikitext)
end

return p