« Module:Documentation » : différence entre les versions
Aller à la navigation
Aller à la recherche
Modèle>Hlm Z. (utilisation de mw.title pour docname()) |
Modèle>Hlm Z. Aucun résumé des modifications |
||
| Ligne 6 : | Ligne 6 : | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local corps = {} | local corps = {} | ||
--Bandeau pour les sous-pages /Bac à sable | --Bandeau pour les sous-pages /Bac à sable | ||
if | if mw.title.getCurrentTitle().subpageText == 'Bac à sable' then | ||
table.insert(corps, '<div style="clear:both />') | table.insert(corps, '<div style="clear:both />') | ||
table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}')) | table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}')) | ||
| Ligne 24 : | Ligne 24 : | ||
return table.concat(corps) | return table.concat(corps) | ||
end | end | ||
| Ligne 95 : | Ligne 95 : | ||
table.insert(entete, ']</span>') | table.insert(entete, ']</span>') | ||
end | end | ||
table.insert(entete, '</div>') | table.insert(entete, '</div>') | ||
return table.concat(entete) | return table.concat(entete) | ||
| Ligne 119 : | Ligne 119 : | ||
table.insert(contenu, frame:preprocess('\n<nowiki /><div style="clear:both" />\n')) | table.insert(contenu, frame:preprocess('\n<nowiki /><div style="clear:both" />\n')) | ||
return table.concat(contenu) | return table.concat(contenu) | ||
end | end | ||
function p.notice(frame, args) | function p.notice(frame, args) | ||
local notice = {} | local notice = {} | ||
if args.contenu then | if args.contenu then | ||
table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">') | table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">') | ||
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n') | table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n') | ||
if args.notice then | if args.notice then | ||
table.insert(notice, args.notice) | table.insert(notice, args.notice) | ||
| Ligne 145 : | Ligne 145 : | ||
table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ') | table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ') | ||
table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa ') | table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa ') | ||
if args[1] then | if args[1] then | ||
table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]') | table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]') | ||
| Ligne 151 : | Ligne 151 : | ||
table.insert(notice, '[[' .. p.docname(frame) .. '|sous-page de documentation]]') | table.insert(notice, '[[' .. p.docname(frame) .. '|sous-page de documentation]]') | ||
end | end | ||
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(') | table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(') | ||
table.insert(notice, '[{{fullurl:') | table.insert(notice, '[{{fullurl:') | ||
| Ligne 170 : | Ligne 170 : | ||
end | end | ||
table.insert(notice, 'Les éditeurs peuvent travailler dans le ') | table.insert(notice, 'Les éditeurs peuvent travailler dans le ') | ||
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}')) | if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}')) | ||
or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Bac à sable}}')) then | or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Bac à sable}}')) then | ||
| Ligne 200 : | Ligne 200 : | ||
end | end | ||
table.insert(notice, ' et la page de ') | table.insert(notice, ' et la page de ') | ||
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}')) | if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}')) | ||
or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Test}}')) then | or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Test}}')) then | ||
| Ligne 239 : | Ligne 239 : | ||
end | end | ||
table.insert(notice, '|action=edit') | table.insert(notice, '|action=edit') | ||
else | else | ||
if args[1] then | if args[1] then | ||
Version du 22 juillet 2013 à 17:37
La documentation pour ce module peut être créée à Module:Documentation/doc
--Ce module implemente le modèle {{Documentation}}.
local p = {}
function p.corps(frame)
local args = frame:getParent().args
local corps = {}
--Bandeau pour les sous-pages /Bac à sable
if mw.title.getCurrentTitle().subpageText == 'Bac à sable' then
table.insert(corps, '<div style="clear:both />')
table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
end
--Génération de la documentation
table.insert(corps, frame:preprocess(p.entete(frame, args)))
table.insert(corps, p.contenu(frame, args))
table.insert(corps, frame:preprocess(p.notice(frame, args)))
--Code HTML brut
if args.raw then
return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>')
end
return table.concat(corps)
end
function p.ifexist(page)
if not page then return false end
if mw.title.new(page).exists then return true end
return false
end
function p.docname(frame)
local page = mw.title.getCurrentTitle()
if not page.isSubpage then
--On n'est pas dans une sous-page
return page.subjectNsText .. ":" .. page.text .. "/Documentation"
else
--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
end
function p.entete(frame, args)
local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
if not args.couleur then
table.insert(entete, '#ecfcf4')
else
table.insert(entete, args.couleur)
end
table.insert(entete, '; padding:1em 1em 0.8em;">')
table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
table.insert(entete, '<span style="font-weight:bold; font-size:125%"> ')
if args.titre then
table.insert(entete, args.titre)
else
table.insert(entete, 'Documentation')
end
table.insert(entete, '</span>')
if not args.contenu then
table.insert(entete, '<span id="doc_editlinks" class="mw-editsection plainlinks">[[')
table.insert(entete, '{{fullurl:')
if args[1] then
if p.ifexist(args[1]) then
table.insert(entete, args[1])
table.insert(entete, '|action=edit modifier}}]] [{{Purger le cache|purger}}')
else
table.insert(entete, args[1])
table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
end
else
if p.ifexist(p.docname(frame)) then
table.insert(entete, p.docname(frame))
table.insert(entete, '|action=edit modifier}}]] [{{Purger le cache|purger}}')
else
table.insert(entete, p.docname(frame))
table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
end
end
table.insert(entete, ']</span>')
end
table.insert(entete, '</div>')
return table.concat(entete)
end
function p.contenu(frame, args)
local contenu = {}
if args.contenu then
table.insert(contenu, '\n')
table.insert(contenu, args.contenu)
else
table.insert(contenu, frame:preprocess('<nowiki />\n'))
--Évite toute récursion
if args[1]
and frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. args[1] .. '}}')
and p.ifexist(args[1]) then
table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. p.docname(frame) .. '}}')
and p.ifexist(p.docname(frame)) then
table.insert(contenu, frame:preprocess('{{' .. p.docname(frame) .. '}}'))
end
end
table.insert(contenu, frame:preprocess('\n<nowiki /><div style="clear:both" />\n'))
return table.concat(contenu)
end
function p.notice(frame, args)
local notice = {}
if args.contenu then
table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n')
if args.notice then
table.insert(notice, args.notice)
else
table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce [[Aide:Modèle|modèle]] ')
table.insert(notice, 'est directement [[Aide:Inclusion|incluse]] dans le corps de ce dernier.<br />')
table.insert(notice, 'Si cette page est protégée, veuillez transférer le contenu de la documentation vers sa ')
table.insert(notice, '[{{fullurl:' .. p.docname(frame))
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload sous-page dédiée}}].')
end
else
if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(frame)) then
table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ')
table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa ')
if args[1] then
table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]')
else
table.insert(notice, '[[' .. p.docname(frame) .. '|sous-page de documentation]]')
end
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:')
if args[1] then
table.insert(notice, args[1] .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, args[1] .. '|action=history}} historique]')
else
table.insert(notice, p.docname(frame) .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, p.docname(frame) .. '|action=history}} historique]')
end
table.insert(notice, ')</span>.<br />')
else
table.insert(notice, '<div class="plainlinks">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
end
table.insert(notice, 'Les éditeurs peuvent travailler dans le ')
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}'))
or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Bac à sable}}')) then
table.insert(notice, '[[{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Bac à sable}}|bac à sable]]')
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>')
else
table.insert(notice, 'bac à sable <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Bac à sable}}|action=edit&preload=Modèle:Documentation/Preload2}} créer]')
table.insert(notice, ')</span>')
end
table.insert(notice, ' et la page de ')
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}'))
or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Test}}')) then
table.insert(notice, '[[{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Test}}|test]]')
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Test}}|action=edit}} modifier])</span>')
else
table.insert(notice, 'test <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '/../Test}}|action=edit&preload=Modèle:Documentation/Preload3}} créer]')
table.insert(notice, ')</span>')
end
table.insert(notice, '.<br />Veuillez placer les catégories dans la sous-page ')
table.insert(notice, '<span class="plainlinks">[')
table.insert(notice, '{{fullurl:')
if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(frame)) then
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '|action=edit')
else
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, p.docname(frame))
end
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')
end
table.insert(notice, ' /Documentation}}].')
end
table.insert(notice, '</p></div></div>')
return table.concat(notice)
end
return p