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)
m Espace insécable
Hiob (discussion | contributions)
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 customLabel = args[2]
     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 avec classes CSS
     -- Construction du style
     local style = string.format(
     local style = string.format(
         'class="table-color-cell table-color-%s" style="background-color: %s; color: %s"',
         'background-color: %s; color: %s',
        colorName:gsub("%W", "-"),
         color.bg,
         color.bg,
         color.fg
         color.fg
     )
     )
      
      
     -- Traitement du label
     -- Si pas de contenu ou contenu vide
     if customLabel then
     if not content or mw.text.trim(content) == "" then
        local labelTrimmed = mw.text.trim(customLabel)
        return 'style="' .. style .. '"'
        -- Si le label existe et n'est pas vide
        if labelTrimmed ~= "" then
            return style .. ' | ' .. customLabel
        end
     end
     end
      
      
     -- Si pas de label ou label vide, retourner juste le style sans le séparateur
     -- 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"\n! Nom !! Aperçu !! Code\n'
     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 = output .. string.format(
         table.insert(output, '|-')
             '|-\n| %s || style="background:%s; color:%s; padding:5px 10px;" | %s || <code>{{Couleur|%s}}</code>\n',
        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
      
      
     return output .. '|}'
     table.insert(output, '|}')
   
    return table.concat(output, '\n')
end
end


return p
return p