« Module:Documentation » : différence entre les versions
documentation demandé par Zebulon84 |
à la demande de son auteur (Hlm Z.) |
||
Ligne 1 : | Ligne 1 : | ||
--Ce module implémente le modèle {{Documentation}}. | --Ce module implémente le modèle {{Documentation}}. | ||
local p = {} | local p = {} | ||
local TableBuilder = require('Module:TableBuilder') | |||
function p.corps(frame) | function p.corps(frame) | ||
args = frame:getParent().args | args = frame:getParent().args | ||
local page = mw.title.getCurrentTitle() | local page = mw.title.getCurrentTitle() | ||
doc = p.docname(page) | doc = p.docname(page) | ||
tab = TableBuilder.new() | |||
--Bandeau pour les sous-pages /Bac à sable | --Bandeau pour les sous-pages /Bac à sable | ||
if page.subpageText == 'Bac à sable' then | if page.subpageText == 'Bac à sable' then | ||
tab.insert('<div style="clear:both />') | |||
.insert(frame:preprocess('{{Sous-page de bac à sable}}')) | |||
end | end | ||
--Génération de la documentation | --Génération de la documentation | ||
p.entete(page) | |||
p.contenu(frame, page) | |||
p.notice(page) | |||
return | return tab.concat() | ||
end | end | ||
function p.docname(page) | function p.docname(page) | ||
--On n'est pas dans une sous-page | --On n'est pas dans une sous-page | ||
if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end | if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end | ||
--On est dans une sous-page | --On est dans une sous-page | ||
if page.subpageText == 'Documentation' | if page.subpageText == 'Documentation' | ||
Ligne 41 : | Ligne 38 : | ||
end | end | ||
end | end | ||
function p.ifexist(page) | function p.ifexist(page) | ||
if not page | if not page or not mw.title.new(page).exists then return false end | ||
return true | |||
return | |||
end | end | ||
function p.entete(page) | function p.entete(page) | ||
tab.insert('<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:') | |||
if not args.couleur then | if not args.couleur then tab.insert('#ecfcf4') | ||
else | else tab.insert(args.couleur) end | ||
tab.insert('; padding:1em 1em 0.8em;">') | |||
.insert('<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">') | |||
.insert('[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]') | |||
.insert('<span style="font-weight:bold; font-size:125%"> ') | |||
if args.titre then tab.insert(args.titre) | |||
else tab.insert('Documentation') end | |||
tab.insert('</span>') | |||
tab.insert('<span class="mw-editsection plainlinks">[[') | |||
if args.titre then | if not args.contenu then | ||
else | |||
local arg = mw.title.new(args[1] or doc) | local arg = mw.title.new(args[1] or doc) | ||
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | ||
tab.insert(arg:fullUrl('action=edit')) | |||
.insert(' modifier') | |||
else | else | ||
tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"})) | |||
.insert(' créer') | |||
end | end | ||
tab.insert(']] [[') | |||
end | end | ||
tab.insert(page:fullUrl('action=purge') .. ' purger]') | |||
.insert(']</span></div>') | |||
return tab.concat() | |||
return | |||
end | end | ||
function p.contenu(frame, page) | function p.contenu(frame, page) | ||
local arg = args[1] or doc | local arg = args[1] or doc | ||
if args.contenu then | if args.contenu then | ||
tab.insert('\n') | |||
.insert(args.contenu) | |||
else | else | ||
tab.insert(frame:preprocess('<nowiki />')) | |||
.insert('\n') | |||
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | ||
tab.insert(frame:preprocess('{{' .. arg .. '}}')) | |||
end | end | ||
end | end | ||
tab.insert('\n') | |||
.insert(frame:preprocess('<nowiki />')) | |||
.insert('<div style="clear:both" />\n') | |||
return tab.concat() | |||
return | |||
end | end | ||
function p.notice(page) | function p.notice(page) | ||
local arg = mw.title.new(args[1] or doc) | local arg = mw.title.new(args[1] or doc) | ||
if args.contenu then | if args.contenu then | ||
tab.insert('<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">') | |||
.insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n') | |||
if args.notice then | if args.notice then | ||
tab.insert(args.notice) | |||
else | else | ||
tab.insert('La [[Aide:Documentation de modèle|documentation]] de ce ') | |||
.insert('[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ') | |||
.insert('dans le corps de ce dernier.<br />Si cette page est protégée, ') | |||
.insert('veuillez transférer le contenu de la documentation vers sa [') | |||
.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"})) | |||
.insert(' sous-page dédiée].') | |||
end | end | ||
else | else | ||
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | ||
tab.insert('<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">') | |||
.insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">') | |||
.insert('La [[Aide:Documentation de modèle|documentation]] de ce ') | |||
.insert('[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa [[') | |||
.insert(tostring(arg) .. '|sous-page de documentation]]') | |||
.insert(' <span style="font-size:89%; font-style:normal;">([') | |||
.insert(arg:fullUrl('action=edit')) | |||
.insert(' modifier] | [') | |||
.insert(arg:fullUrl('action=history') .. ' historique])</span>.<br />') | |||
else | else | ||
tab.insert('<div class="plainlinks">') | |||
.insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">') | |||
end | end | ||
tab.insert('Les éditeurs peuvent travailler dans le ') | |||
local bacasable = arg.subjectNsText .. ":" .. arg.baseText .. "/Bac à sable" | local bacasable = arg.subjectNsText .. ":" .. arg.baseText .. "/Bac à sable" | ||
local argbacasable = mw.title.new(bacasable) | local argbacasable = mw.title.new(bacasable) | ||
if p.ifexist(bacasable) then | if p.ifexist(bacasable) then | ||
tab.insert('[[' .. bacasable .. '|bac à sable]]') | |||
.insert(' <span style="font-size:89%; font-style:normal;">([') | |||
.insert(argbacasable:fullUrl('action=edit')) | |||
.insert(' modifier])</span>') | |||
else | else | ||
tab.insert('bac à sable <span style="font-size:89%; font-style:normal;">([') | |||
.insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"})) | |||
.insert(' créer])</span>') | |||
end | end | ||
tab.insert(' et la page de ') | |||
local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test" | local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test" | ||
local argtest = mw.title.new(test) | local argtest = mw.title.new(test) | ||
if p.ifexist(test) then | if p.ifexist(test) then | ||
tab.insert('[[' .. test .. '|test]]') | |||
.insert(' <span style="font-size:89%; font-style:normal;">([') | |||
.insert(argtest:fullUrl('action=edit')) | |||
.insert(' modifier])</span>') | |||
else | else | ||
tab.insert('test <span style="font-size:89%; font-style:normal;">([') | |||
.insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"})) | |||
.insert(' créer])</span>') | |||
end | end | ||
tab.insert('.<br />Veuillez placer les catégories dans la sous-page ') | |||
.insert('<span class="plainlinks">[') | |||
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | ||
tab.insert(arg:fullUrl('action=edit')) | |||
else | else | ||
tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"})) | |||
end | end | ||
tab.insert(' /Documentation].') | |||
end | |||
tab.insert('</p></div></div>') | |||
return tab.concat() | |||
return | |||
end | end | ||
return p | return p |
Version du 2 octobre 2013 à 08:30
--Ce module implémente le modèle Modèle:Méta documentation de modèle.
local p = {}
local TableBuilder = require('Module:TableBuilder')
function p.corps(frame)
args = frame:getParent().args local page = mw.title.getCurrentTitle() doc = p.docname(page) tab = TableBuilder.new()
--Bandeau pour les sous-pages /Bac à sable if page.subpageText == 'Bac à sable' then
tab.insert('
.insert(frame:preprocess('Modèle:Sous-page de bac à sable')) end --Génération de la documentation p.entete(page) p.contenu(frame, page) p.notice(page)
return tab.concat()
end
function p.docname(page)
--On n'est pas dans une sous-page if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end --On est dans une sous-page if page.subpageText == 'Documentation' or page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then return page.subjectNsText .. ":" .. page.baseText .. "/Documentation" else return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
end
function p.ifexist(page)
if not page or not mw.title.new(page).exists then return false end return true
end
function p.entete(page)
tab.insert('.insert('') .insert(' ')
if args.titre then tab.insert(args.titre) else tab.insert('Documentation') end tab.insert('')
tab.insert('[[') if not args.contenu then
local arg = mw.title.new(args[1] or doc)
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then tab.insert(arg:fullUrl('action=edit')) .insert(' modifier') else tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"})) .insert(' créer') end tab.insert(']] [[') end tab.insert(page:fullUrl('action=purge') .. ' purger]').insert(']
return tab.concat()
end
function p.contenu(frame, page)
local arg = args[1] or doc
if args.contenu then tab.insert('\n') .insert(args.contenu) else tab.insert(frame:preprocess('')) .insert('\n') if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then tab.insert(frame:preprocess('Modèle:' .. arg .. '')) end end tab.insert('\n') .insert(frame:preprocess('')).insert('
return tab.concat()
end
function p.notice(page)
local arg = mw.title.new(args[1] or doc) if args.contenu thentab.insert('
\n')
if args.notice then
tab.insert(args.notice)
else
tab.insert('La documentation de ce ')
.insert('modèle est directement incluse ')
.insert('dans le corps de ce dernier.
Si cette page est protégée, ')
.insert('veuillez transférer le contenu de la documentation vers sa [')
.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
.insert(' sous-page dédiée].')
end
else
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
tab.insert('
')
.insert('La documentation de ce ')
.insert('modèle est incluse depuis sa [[')
.insert(tostring(arg) .. '|sous-page de documentation]]')
.insert(' ([')
.insert(arg:fullUrl('action=edit'))
.insert(' modifier] | [')
.insert(arg:fullUrl('action=history') .. ' historique]).
')
else
tab.insert('
')
end
tab.insert('Les éditeurs peuvent travailler dans le ')
local bacasable = arg.subjectNsText .. ":" .. arg.baseText .. "/Bac à sable"
local argbacasable = mw.title.new(bacasable)
if p.ifexist(bacasable) then
tab.insert('bac à sable')
.insert(' ([')
.insert(argbacasable:fullUrl('action=edit'))
.insert(' modifier])')
else
tab.insert('bac à sable ([')
.insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
.insert(' créer])')
end
tab.insert(' et la page de ')
local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test"
local argtest = mw.title.new(test)
if p.ifexist(test) then
tab.insert('test')
.insert(' ([')
.insert(argtest:fullUrl('action=edit'))
.insert(' modifier])')
else
tab.insert('test ([')
.insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
.insert(' créer])')
end
tab.insert('.
Veuillez placer les catégories dans la sous-page ')
.insert('[')
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
tab.insert(arg:fullUrl('action=edit'))
else
tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
end
tab.insert(' /Documentation].')
end
tab.insert('
return tab.concat()
end
return p