Aller au contenu

Module:Infobox/Test

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 20 février 2014 à 21:48 et modifiée en dernier par Zolo (discuter | contributions) (Nouvelle page : local Infobox = {} local externaltext = '' -- maintenance category, coordinates outside infobox etc. that appear outside the infobox local i18n = { ['see doc'] = 'Documentation...). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

 Documentation[voir] [modifier] [historique] [purger]

Cette page définit un module d'infobox.


local Infobox = {}
local externaltext = '' -- maintenance category, coordinates outside infobox etc. that appear outside the infobox

local i18n = {
	['see doc'] = 'Documentation du modèle',
	['edit infobox'] = 'Modifier l\'infobox',
	['errorcat'] = 'Page avec un modèle d\'infobox incorrect',
}

function makecat(cat, sortkey)
	return '[[Category:' .. args.cat .. '|' .. args.sortkey .. ']]'
end

local infobox = mw.html.create('div')

function Infobox:addTitle( args )
    local class = args.class or 'entete'
    local text = args.text or mw.title.getCurrentTitle().text
    local style = args.style or ''

	infobox:tag('p')
		:addClass(class)
		:cssText(style)
		:wikitext(text)
		:done()
end

function Infobox:addText( args )
    local class = args.class
    local text = args.text
    local style = args.style or ''

	infobox:tag('p')
		:addClass(class)
		:cssText(style)
		:wikitext(text)
		:done()
end


function Infobox:addMixedRow( args )
	local value = args.value
	if not value and args.cat then
		externaltext = externaltext ..  makecat(args.cat, args.sortkey)
	end
	
    local label = args.label
    if not label then
        label = '<td class="error">Le paramètre label n\'est pas renseigné.</td></tr>'
        externaltext = externaltext .. makecat(i18n['errorcat'])
    end
   if not value then 
   		return
   	end
   	
	if args.hidden then
		value = tostring(mw.html.create('div')
					:addClass("NavFrame")
					:cssText('title="[Afficher]/[Masquer]" style="border: none; padding: 0;"><div class="NavContent" style="display: none; text-align: left;">' .. args.value ..'</div></div></td></tr>')
				)
	end
	if args.weblink then
		value = '<span class="reflink plainlinksneverexpand">[' .. args.weblink .. args.value .. ' ' .. args.value .. ']</span></td></tr>'
	end
	
    infobox:tag('tr')
		:tag('th')
--			:style('styleHeader')
			:css('scope', 'row')
			:wikitext(label)
			:done()
		:tag('th')
			:wikitext(value)
			:done()
		:done()
		
end