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)
Parsed frame:preprocess()
Hiob (discussion | contributions)
Aucun résumé des modifications
Ligne 35 : Ligne 35 :


-- Fonction principale pour styliser une cellule
-- Fonction principale pour styliser une cellule
function p.style(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] or ""
      
      
     -- 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 de la balise span colorée
     local style = string.format(
     return frame:preprocess(string.format(
         'style="background-color: %s; color: %s"',
         '<span style="background-color: %s; color: %s; padding: 2px 8px; border-radius: 3px; display: inline-block;">%s</span>',
         color.bg,
         color.bg,
         color.fg
         color.fg,
    )
        content ~= "" and content or "&nbsp;"
   
     ))
    -- 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
end


Ligne 88 : Ligne 76 :
     for _, name in ipairs(sorted) do
     for _, name in ipairs(sorted) do
         local color = colors[name]
         local color = colors[name]
         local row = string.format(
         table.insert(rows, string.format(
             '|-\n| %s || style="background:%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}}</code>',
             color.label,
             color.label,
             color.bg,
             color.bg,
Ligne 95 : Ligne 83 :
             color.label,
             color.label,
             name
             name
         )
         ))
        table.insert(rows, row)
     end
     end
      
      
Ligne 104 : Ligne 91 :
         .. '\n|}'
         .. '\n|}'
      
      
    -- Parser le wikitext avant de le retourner
     return frame:preprocess(wikitext)
     return frame:preprocess(wikitext)
end
end


return p
return p