« Module:TableColors » : différence entre les versions
De Nefald
Autres actions
cellule pleine |
m Avec ou sans tableau |
||
Ligne 34 : | Ligne 34 : | ||
} | } | ||
-- Fonction principale | -- 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 | -- 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, | -- 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 ' | return '' | ||
end | end | ||
return string.format( | |||
'<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, |