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)
cellule pleine
Hiob (discussion | contributions)
m Avec ou sans tableau
Ligne 34 : Ligne 34 :
}
}


-- Fonction principale pour styliser une cellule
-- Fonction principale unifiée
function p.cell(frame)
function p.cell(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]
     local content = args[2]
    local mode = mw.text.trim(args.mode or args[3] or "auto"):lower()
      
      
     -- Gestion des alias
     -- Gestion des alias
Ligne 53 : Ligne 54 :
     local color = colors[colorName] or colors.light
     local color = colors[colorName] or colors.light
      
      
     -- Construction des attributs de style
     -- Construction du style
     local styleAttr = string.format(
     local styleAttr = string.format(
         'background-color:%s; color:%s; padding:8px 12px;',
         'background-color:%s; color:%s; padding:8px 12px;',
Ligne 60 : Ligne 61 :
     )
     )
      
      
     -- Si pas de contenu, retourner juste le style (cellule vide colorée)
     -- Détection automatique du contexte
    if mode == "auto" then
        -- Si pas de contenu, c'est probablement pour un tableau
        if not content or mw.text.trim(content) == "" then
            mode = "table"
        else
            mode = "span"
        end
    end
   
    -- Mode tableau (pour les cellules)
    if mode == "table" or mode == "cellule" then
        if not content or mw.text.trim(content) == "" then
            return 'style="' .. styleAttr .. '" | '
        end
        return 'style="' .. styleAttr .. '" | ' .. content
    end
   
    -- Mode span (pour le texte normal)
     if not content or mw.text.trim(content) == "" then
     if not content or mw.text.trim(content) == "" then
         return 'style="' .. styleAttr .. '" | '
         return ''
     end
     end
      
      
     -- Si contenu présent, retourner style + contenu
     return string.format(
    return 'style="' .. styleAttr .. '" | ' .. content
        '<span style="%s">%s</span>',
        styleAttr,
        content
    )
end
end


Ligne 84 : Ligne 106 :
         local color = colors[name]
         local color = colors[name]
         table.insert(rows, string.format(
         table.insert(rows, string.format(
             '|-\n| %s || style="background-color:%s; color:%s; padding:8px 15px; font-weight:500;" | %s || <code>{{Couleur|%s}}</code>',
             '|-\n| %s || style="background-color:%s; color:%s; padding:8px 15px; font-weight:500;" | %s || <code>{{Couleur|%s|Exemple}}</code>',
             color.label,
             color.label,
             color.bg,
             color.bg,