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:Infobox/Core » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Aucun résumé des modifications
Balises : Modification par mobile Modification par le web mobile
Hiob (discussion | contributions)
erreur suite implémentation CSS
Ligne 1 : Ligne 1 :
local core = require('Module:Infobox/Core')
local p = {}
local configs = require('Module:Infobox/Configs')
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


local p = {}
function p.build(args, config)
    if not args.nom or args.nom == '' then
        return '<div class="error">Nom requis pour l\'infobox</div>'
    end
 
    local root = mw.html.create('div')
        :addClass('infobox-table')
        :attr('role', 'table')


function p.main(frame)
    -- En-tête avec nom
    local args = getArgs(frame, {parentFirst = true})
    local header = mw.html.create('div')
        :addClass('infobox-header')
      
      
     local infoboxType = args.type or 'monde'
     if args.image and args.image ~= '' then
    local config = configs[infoboxType]
        local imageDiv = mw.html.create('div')
      
            :addClass('infobox-image')
     if not config then
       
         return '<div class="error">Type d\'infobox non reconnu : ' .. (infoboxType or 'non spécifié') .. '</div>'
        local imageSize = args.tailleimage or '280px'
        local imageCode = string.format('[[Fichier:%s|%s|center', args.image, imageSize)
        if args.legende and args.legende ~= '' then
            imageCode = imageCode .. '|' .. args.legende
        end
        imageCode = imageCode .. ']]'
       
        imageDiv:wikitext(imageCode)
        header:node(imageDiv)
     end
 
    local titleDiv = mw.html.create('div')
        :addClass('infobox-title')
        :wikitext(args.nom)
    header:node(titleDiv)
 
     if args.soustitre and args.soustitre ~= '' then
         local subtitleDiv = mw.html.create('div')
            :addClass('infobox-subtitle')
            :wikitext(args.soustitre)
        header:node(subtitleDiv)
    end
 
    root:node(header)
 
    -- Corps avec les champs
    local body = mw.html.create('div')
        :addClass('infobox-body')
 
    for _, section in ipairs(config.sections or {}) do
        if section.titre then
            local sectionDiv = mw.html.create('div')
                :addClass('infobox-section-title')
                :wikitext(section.titre)
            body:node(sectionDiv)
        end
 
        for _, champ in ipairs(section.champs or {}) do
            if args[champ.cle] and args[champ.cle] ~= '' then
                local rowDiv = mw.html.create('div')
                    :addClass('infobox-row')
 
                local labelDiv = mw.html.create('div')
                    :addClass('infobox-label')
                    :wikitext(champ.label)
               
                local valueDiv = mw.html.create('div')
                    :addClass('infobox-value')
                    :wikitext(args[champ.cle])
 
                rowDiv:node(labelDiv):node(valueDiv)
                body:node(rowDiv)
            end
        end
     end
     end
   
 
    -- CSS intégré directement
     root:node(body)
     local cssContent = frame:extensionTag('templatestyles', '', {src = 'Modèle:Infobox/styles.css'})
     return tostring(root)
   
     return cssContent .. core.build(args, config)
end
end


return p
return p

Version du 23 septembre 2025 à 19:26

La documentation pour ce module peut être créée à Module:Infobox/Core/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.build(args, config)
    if not args.nom or args.nom == '' then
        return '<div class="error">Nom requis pour l\'infobox</div>'
    end

    local root = mw.html.create('div')
        :addClass('infobox-table')
        :attr('role', 'table')

    -- En-tête avec nom
    local header = mw.html.create('div')
        :addClass('infobox-header')
    
    if args.image and args.image ~= '' then
        local imageDiv = mw.html.create('div')
            :addClass('infobox-image')
        
        local imageSize = args.tailleimage or '280px'
        local imageCode = string.format('[[Fichier:%s|%s|center', args.image, imageSize)
        if args.legende and args.legende ~= '' then
            imageCode = imageCode .. '|' .. args.legende
        end
        imageCode = imageCode .. ']]'
        
        imageDiv:wikitext(imageCode)
        header:node(imageDiv)
    end

    local titleDiv = mw.html.create('div')
        :addClass('infobox-title')
        :wikitext(args.nom)
    header:node(titleDiv)

    if args.soustitre and args.soustitre ~= '' then
        local subtitleDiv = mw.html.create('div')
            :addClass('infobox-subtitle')
            :wikitext(args.soustitre)
        header:node(subtitleDiv)
    end

    root:node(header)

    -- Corps avec les champs
    local body = mw.html.create('div')
        :addClass('infobox-body')

    for _, section in ipairs(config.sections or {}) do
        if section.titre then
            local sectionDiv = mw.html.create('div')
                :addClass('infobox-section-title')
                :wikitext(section.titre)
            body:node(sectionDiv)
        end

        for _, champ in ipairs(section.champs or {}) do
            if args[champ.cle] and args[champ.cle] ~= '' then
                local rowDiv = mw.html.create('div')
                    :addClass('infobox-row')

                local labelDiv = mw.html.create('div')
                    :addClass('infobox-label')
                    :wikitext(champ.label)
                
                local valueDiv = mw.html.create('div')
                    :addClass('infobox-value')
                    :wikitext(args[champ.cle])

                rowDiv:node(labelDiv):node(valueDiv)
                body:node(rowDiv)
            end
        end
    end

    root:node(body)
    return tostring(root)
end

return p