« Module:TableColors » : différence entre les versions
De Nefald
Autres actions
m Espace insécable |
mAucun résumé des modifications |
||
Ligne 38 : | Ligne 38 : | ||
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 | local content = args[2] -- Ne pas trim ici pour garder le formatage | ||
-- Gestion des alias | -- Gestion des alias | ||
Ligne 53 : | Ligne 53 : | ||
local color = colors[colorName] or colors.light | local color = colors[colorName] or colors.light | ||
-- Construction du style | -- Construction du style | ||
local style = string.format( | local style = string.format( | ||
' | 'background-color: %s; color: %s', | ||
color.bg, | color.bg, | ||
color.fg | color.fg | ||
) | ) | ||
-- | -- Si pas de contenu ou contenu vide | ||
if | if not content or mw.text.trim(content) == "" then | ||
return 'style="' .. style .. '"' | |||
end | end | ||
-- Si | -- Si contenu présent | ||
return style | return 'style="' .. 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 = '{| class="wikitable sortable" | local output = {} | ||
table.insert(output, '{| class="wikitable sortable"') | |||
table.insert(output, '! Nom !! Aperçu !! Code') | |||
local sorted = {} | local sorted = {} | ||
Ligne 86 : | Ligne 83 : | ||
for _, name in ipairs(sorted) do | for _, name in ipairs(sorted) do | ||
local color = colors[name] | local color = colors[name] | ||
output | table.insert(output, '|-') | ||
' | table.insert(output, string.format( | ||
'| %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 93 : | Ligne 91 : | ||
color.label, | color.label, | ||
name | name | ||
) | )) | ||
end | end | ||
table.insert(output, '|}') | |||
return table.concat(output, '\n') | |||
end | end | ||
return p | return p |