Différences entre les versions de « Module:Boîte d'informations »
| Ligne 57 : | Ligne 57 : | ||
end | end | ||
if args['image'] ~= nil and args['image'] ~= '' then | if args['galerie'] ~= nil and args['galerie'] ~= '' then | ||
output:node(args['galerie']) | |||
elseif args['image'] ~= nil and args['image'] ~= '' then | |||
output | output | ||
:tag('p') | :tag('p') | ||
Version actuelle datée du 23 novembre 2023 à 20:30
Syntaxe
| Type | Clé associée | Couleur | Type | Clé associée | Couleur |
|---|---|---|---|---|---|
| Personnage | character
|
light-yellow | Tribu Aielle | aielClan
|
light-purple |
| Lieu | location
|
light-blue | Clan Aiel | aielSept
|
light-pink |
| Livre | book
|
light-green | Société Guerrière Aielle | aielWarriorSociety
|
light-orange |
| Objet | item
|
light-red | Épisode TV | tvEpisode
|
purple |
| Commerce | merchant
|
blue | |||
| Ajah | ajah
|
#1c2677 #b51a1c #fcfdff #3c833b #a56635 #e1bd15 #737886 #000000
|
|||
| Traductions | translation
|
Couleurs libres : light-red, light-purple, purple.
Boîte d'informations
{{#invoke:Boîte d'informations|buildBox
| type =
| Paramètres de la boîte d'informations
|}
Si le type n'est pas renseigné, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations non renseigné, s'il n'existe pas, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations inconnu.
Syntaxe
{{#invoke:Boîte d'informations|buildSyntax|type=...}}
Si nécessaire, les expressions régulières suivantes peuvent être utilisées dans Notepad++ pour créer automatiquement les emplacements de paramètres dans le modèle.
\| ([^=]+) =
| \1 = {{{\1|}}}
Si le type n'est pas renseigné, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations non renseigné, s'il n'existe pas, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations inconnu.
Tableau de paramètres
{{#invoke:Boîte d'informations|buildParameters|type=...}}
Si le type n'est pas renseigné, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations non renseigné, s'il n'existe pas, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations inconnu.
Exemple
{{#invoke:Boîte d'informations|buildExemple|type=...|modelName={{PAGENAME}}}}
Si le type n'est pas renseigné, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations non renseigné, s'il n'existe pas, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles de boîte d'informations inconnu. De plus, si le nom du modèle n'est pas renseigné, la page sera marquée comme appartenant à la catégorie Catégorie:Page avec des modèles non renseigné.
Références
local p = {}
local settings = require('Module:Boîte d\'informations (Configuration)')
-- Utility functions
local function buildSection(output, title, tag)
tag = tag or 'table'
if title ~= nil and title ~= '' then
return output
:tag('p')
:addClass('mw-section-title')
:wikitext(title)
:done()
:tag(tag)
else
return output:tag(tag)
end
end
-- Function to build a box
function p.buildBox(frame)
local moduleArgs = frame.args
local args = frame:getParent().args
if moduleArgs['type'] == nil or moduleArgs['type'] == ''then
return '[[Catégorie:Page avec des modèles de boîte d\'informations non renseigné]]'
elseif settings.availableBoxes[moduleArgs['type']] == nil then
return '[[Catégorie:Page avec des modèles de boîte d\'informations inconnu]]'
end
local sections = settings.availableBoxes[moduleArgs['type']]
local output = mw.html.create('div')
output:addClass('mw-information-box')
if moduleArgs['classes'] ~= nil and moduleArgs['classes'] ~= '' then
output:addClass(moduleArgs['classes'])
end
if args['classes'] ~= nil and args['classes'] ~= '' then
output:addClass(args['classes'])
end
-- Common parameters
if args['titre'] ~= nil and args['titre'] ~= '' then
output
:tag('p')
:addClass('mw-title')
:wikitext(args['titre'])
end
if args['sous titre'] ~= nil and args['sous titre'] ~= '' then
output
:tag('p')
:addClass('mw-sub-title')
:wikitext(args['sous titre'])
end
if args['galerie'] ~= nil and args['galerie'] ~= '' then
output:node(args['galerie'])
elseif args['image'] ~= nil and args['image'] ~= '' then
output
:tag('p')
:addClass('mw-image')
:wikitext('[[Image:' .. args['image'] .. '|290px]]')
end
if args['légende'] ~= nil and args['légende'] ~= '' then
output
:tag('p')
:addClass('mw-caption')
:wikitext(args['légende'])
end
-- Sections
local displaySection, section
for i = 1, #sections do
-- Initialize vars
displaySection = false
section = nil
type = sections[i].type ~= nil and sections[i].type ~= '' and sections[i].type or 'list'
if 'list' == type then
-- Go over pre-defined keys
for j, item in ipairs(sections[i].items) do
if args[item.key] ~= nil and args[item.key] ~= '' then
-- Has the section already started?
if not displaySection then
section = buildSection(output, sections[i].title or nil)
displaySection = true
end
section
:tag('tr')
:tag('th')
:wikitext(item.title)
:done()
:tag('td')
:wikitext(args[item.key])
end
end
-- Free value
if
(args['libellé libre ' .. i] ~= nil and args['libellé libre ' .. i] ~= '')
and
(args['valeur libre ' .. i] ~= nil and args['valeur libre ' .. i] ~= '')
then
if not displaySection then
section = buildSection(output, sections[i].title or nil)
end
section
:tag('tr')
:tag('th')
:wikitext(args['libellé libre ' .. i])
:done()
:tag('td')
:wikitext(args['valeur libre ' .. i])
end
elseif 'free' == type then
if
sections[i].key ~= nil and sections[i].key ~= ''
and
args[sections[i].key] ~= nil and args[sections[i].key] ~= ''
then
section = buildSection(output, sections[i].title or nil, 'div')
section:wikitext(args[sections[i].key])
end
end
end
return tostring(output)
end
-- Function to build the syntax
function p.buildSyntax(frame)
local args = frame.args
if args['type'] == nil or args['type'] == ''then
return '[[Catégorie:Page avec des modèles de boîte d\'informations non renseigné]]'
elseif settings.availableBoxes[args['type']] == nil then
return '[[Catégorie:Page avec des modèles de boîte d\'informations inconnu]]'
end
local sections = settings.availableBoxes[args['type']]
local pre = mw.html.create('pre')
local row
local title = frame:getParent():getTitle()
title = '' .. string.sub(title, string.find(title, ':', 0, true) + 1)
pre:node('{{' .. (args['modèle'] or title)):newline()
-- Common parameters
for i = 1, #settings.commonParameters do
pre:node('| ' .. settings.commonParameters[i].key ..' = '):newline()
end
-- Box specific parameters
for i = 1, #sections do
local type = sections[i].type ~= nil and sections[i].type ~= '' and sections[i].type or 'list'
pre:node('<!-- ' .. (sections[i].title or 'Section sans titre') .. ' -->'):newline()
if 'list' == type then
for j = 1, #sections[i].items do
pre:node('| ' .. sections[i].items[j].key ..' = '):newline()
end
pre:node('| libellé libre ' .. i .. ' = '):newline()
pre:node('| valeur libre ' .. i .. ' = '):newline()
elseif 'free' == type then
if sections[i].key ~= nil and sections[i].key ~= '' then
pre:node('| ' .. sections[i].key .. ' = '):newline()
else
pre:node('<!-- Clé manquante -->')
end
end
end
pre:node('}}')
return tostring(pre)
end
-- Function to build the parameters list
function p.buildParameters(frame)
local args = frame.args
if args['type'] == nil or args['type'] == ''then
return '[[Catégorie:Page avec des modèles de boîte d\'informations non renseigné]]'
elseif settings.availableBoxes[args['type']] == nil then
return '[[Catégorie:Page avec des modèles de boîte d\'informations inconnu]]'
end
local sections = settings.availableBoxes[args['type']]
local table = mw.html.create('table')
local row
table
:addClass('wikitable')
:tag('tr')
:tag('th'):node('Clé'):done()
:tag('th'):node('Titre'):done()
:tag('th'):node('Description')
table
:tag('tr')
:tag('th')
:attr('colspan', '3')
:wikitext('Paramètres communs')
for i = 1, #settings.commonParameters do
row = table:tag('tr')
if settings.commonParameters[i].key ~= nil and settings.commonParameters[i].key ~= '' then
row:tag('td'):node(settings.commonParameters[i].key)
else
row:tag('td'):node('Inconnu')
end
if settings.commonParameters[i].title ~= nil and settings.commonParameters[i].title ~= '' then
row:tag('td'):wikitext(settings.commonParameters[i].title)
else
row:tag('td')
end
if settings.commonParameters[i].description ~= nil and settings.commonParameters[i].description ~= '' then
row:tag('td'):wikitext(settings.commonParameters[i].description)
else
row:tag('td')
end
end
for i = 1, #sections do
local type = sections[i].type ~= nil and sections[i].type ~= '' and sections[i].type or 'list'
if sections[i].title ~= nil and sections[i].title ~= '' then
table
:tag('tr')
:tag('th'):attr('colspan', '3'):wikitext(sections[i].title)
else
table
:tag('tr')
:tag('th'):attr('colspan', '3'):wikitext('Section sans titre')
end
if 'list' == type then
for j = 1, #sections[i].items do
row = table:tag('tr')
if sections[i].items[j].key ~= nil and sections[i].items[j].key ~= '' then
row:tag('td'):node(sections[i].items[j].key)
else
row:tag('td'):node('')
end
if sections[i].items[j].title ~= nil and sections[i].items[j].title ~= '' then
row:tag('td'):wikitext(sections[i].items[j].title)
else
row:tag('td'):node('')
end
if sections[i].items[j].description ~= nil and sections[i].items[j].description ~= '' then
row:tag('td'):wikitext(sections[i].items[j].description)
else
row:tag('td'):node('')
end
end
table
:tag('tr')
:tag('td'):node('libellé libre ' .. i):done()
:tag('td'):node(''):done()
:tag('td'):wikitext('Titre de la valeur libre de la section'):done()
:done()
:tag('tr')
:tag('td'):node('valeur libre ' .. i):done()
:tag('td'):node(''):done()
:tag('td'):wikitext('Valeur libre de la section')
elseif 'free' == type then
if sections[i].key ~= nil and sections[i].key ~= '' then
table
:tag('tr')
:tag('td'):node(sections[i].key):done()
:tag('td'):node(''):done()
:tag('td'):wikitext('Texte libre'):done()
else
table
:tag('tr')
:tag('td'):attr('colspan', '3'):node('Clé manquante')
end
end
end
return tostring(table)
end
-- Function to build the example
function p.buildExample(frame)
local args = frame.args
if args['type'] == nil or args['type'] == ''then
return '[[Catégorie:Page avec des modèles de boîte d\'informations non renseigné]]'
elseif settings.availableBoxes[args['type']] == nil then
return '[[Catégorie:Page avec des modèles de boîte d\'informations inconnu]]'
elseif args['modelName'] == nil or args['modelName'] == '' then
return '[[Catégorie:Page avec des modèles non renseigné]]'
end
local sections = settings.availableBoxes[args['type']]
local wikitext = ''
wikitext = '{{' .. args['modelName'] .. '\n'
-- Common parameters
wikitext = wikitext .. '| titre = <nowiki>{{titre}}</nowiki> \n'
wikitext = wikitext .. '| sous titre = <nowiki>{{sous titre}}</nowiki>\n'
wikitext = wikitext .. '| image = Placeholder-300x400.png\n'
wikitext = wikitext .. '| légende = <nowiki>{{légende}}</nowiki>\n'
for i = 1, #sections do
local type = sections[i].type ~= nil and sections[i].type ~= '' and sections[i].type or 'list'
if sections[i].title ~= nil and sections[i].title ~= '' then
wikitext = wikitext .. '<!-- ' .. sections[i].title .. ' -->\n'
else
wikitext = wikitext .. '<!-- Section sans titre -->\n'
end
if 'list' == type then
for j = 1, #sections[i].items do
if sections[i].items[j].key ~= nil and sections[i].items[j].key ~= '' then
wikitext = wikitext .. '| ' .. sections[i].items[j].key .. ' = <nowiki>{{' .. sections[i].items[j].key .. '}}</nowiki>\n'
end
end
-- Free value
wikitext = wikitext .. '| libellé libre ' .. i .. ' = <nowiki>{{libellé libre ' .. i .. '}}</nowiki>\n'
wikitext = wikitext .. '| valeur libre ' .. i .. ' = <nowiki>{{valeur libre ' .. i .. '}}</nowiki>\n'
elseif 'free' == type then
if sections[i].key ~= nil and sections[i].key ~= '' then
wikitext = wikitext .. '| ' .. sections[i].key .. ' = <nowiki>{{' .. sections[i].key .. '}}</nowiki>\n'
else
wikitext = wikitext .. '<!-- Clé manquante -->\n'
end
end
end
wikitext = wikitext .. '}}'
return frame:preprocess(wikitext)
end
return p