« Module:Documentation » : différence entre les versions

De Le Wiki de Lug
Aller à la navigation Aller à la recherche
Modèle>TigH
(documentation demandé par Zebulon84)
Modèle>FDo64
(à 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)
     local corps = {}
     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
         table.insert(corps, '<div style="clear:both />')
         tab.insert('<div style="clear:both />')
        table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
          .insert(frame:preprocess('{{Sous-page de bac à sable}}'))
     end
     end
 
     --Génération de la documentation
     --Génération de la documentation
     table.insert(corps, p.entete(page))
     p.entete(page)
     table.insert(corps, p.contenu(frame, page))
     p.contenu(frame, page)
     table.insert(corps, p.notice(page))
     p.notice(page)
 
    --Code HTML brut
    if args.raw then
        return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>\n:' .. os.clock())
    end


     return table.concat(corps)
     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 then return false end
     if not page or not mw.title.new(page).exists then return false end
    if mw.title.new(page).exists then return true end
     return true
     return false
end
end
 
function p.entete(page)
function p.entete(page)
     local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
     tab.insert('<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:')


     if not args.couleur then table.insert(entete, '#ecfcf4')
     if not args.couleur then tab.insert('#ecfcf4')
     else table.insert(entete, args.couleur) end
     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%">&nbsp;')


    table.insert(entete, '; padding:1em 1em 0.8em;">')
     if args.titre then tab.insert(args.titre)
    table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
     else tab.insert('Documentation') end
    table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
     tab.insert('</span>')
    table.insert(entete, '<span style="font-weight:bold; font-size:125%">&nbsp;')
 
tab.insert('<span class="mw-editsection plainlinks">&#91;[')
     if args.titre then table.insert(entete, args.titre)
if not args.contenu then
     else table.insert(entete, 'Documentation') end
     table.insert(entete, '</span>')
 
    if not args.contenu then
        table.insert(entete, '<span class="mw-editsection plainlinks">&#91;[')
         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
             table.insert(entete, arg:fullUrl('action=edit') .. ' modifier]')
             tab.insert(arg:fullUrl('action=edit'))
            table.insert(entete, '&#93;&#32;&#91;[')
              .insert(' modifier')
            table.insert(entete, page:fullUrl('action=purge') .. ' purger]')
         else
         else
             table.insert(entete, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
             tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
            table.insert(entete, ' créer]')
              .insert(' créer')
         end
         end
         table.insert(entete, '&#93;</span>')
         tab.insert(']&#93;&#32;&#91;[')
     end
     end
    tab.insert(page:fullUrl('action=purge') .. ' purger]')
      .insert('&#93;</span></div>')


    table.insert(entete, '</div>')
     return tab.concat()
     return table.concat(entete)
end
end
 
function p.contenu(frame, page)
function p.contenu(frame, page)
    local contenu = {}
     local arg = args[1] or doc
     local arg = args[1] or doc
     if args.contenu then
     if args.contenu then
         table.insert(contenu, '\n')
         tab.insert('\n')
        table.insert(contenu, args.contenu)
          .insert(args.contenu)
     else
     else
         table.insert(contenu, frame:preprocess('<nowiki />'))
         tab.insert(frame:preprocess('<nowiki />'))
        table.insert(contenu, '\n')
          .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
             table.insert(contenu, frame:preprocess('{{' .. arg .. '}}'))
             tab.insert(frame:preprocess('{{' .. arg .. '}}'))
         end
         end
     end
     end
    tab.insert('\n')
      .insert(frame:preprocess('<nowiki />'))
      .insert('<div style="clear:both" />\n')


    table.insert(contenu, '\n')
     return tab.concat()
    table.insert(contenu, frame:preprocess('<nowiki />'))
    table.insert(contenu, '<div style="clear:both" />\n')
     return table.concat(contenu)
end
end
 
function p.notice(page)
function p.notice(page)
    local notice = {}
     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
         table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
         tab.insert('<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')
          .insert('<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)
             tab.insert(args.notice)
         else
         else
             table.insert(notice, 'La [[Aide:Documentation de modèle|documentation]] de ce ')
             tab.insert('La [[Aide:Documentation de modèle|documentation]] de ce ')
            table.insert(notice, '[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ')
              .insert('[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ')
            table.insert(notice, 'dans le corps de ce dernier.<br />Si cette page est protégée, ')
              .insert('dans le corps de ce dernier.<br />Si cette page est protégée, ')
            table.insert(notice, 'veuillez transférer le contenu de la documentation vers sa [')
              .insert('veuillez transférer le contenu de la documentation vers sa [')
            table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
              .insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
            table.insert(notice, ' sous-page dédiée].')
              .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
             table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
             tab.insert('<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;">')
              .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
            table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ')
              .insert('La [[Aide:Documentation de modèle|documentation]] de ce ')
            table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa [[')
              .insert('[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa [[')
            table.insert(notice, tostring(arg) .. '|sous-page de documentation]]')
              .insert(tostring(arg) .. '|sous-page de documentation]]')
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(notice, arg:fullUrl('action=edit'))
              .insert(arg:fullUrl('action=edit'))
            table.insert(notice, ' modifier]&nbsp;|&nbsp;[')
              .insert(' modifier]&nbsp;|&nbsp;[')
            table.insert(notice, arg:fullUrl('action=history') .. ' historique])</span>.<br />')
              .insert(arg:fullUrl('action=history') .. ' historique])</span>.<br />')
         else
         else
             table.insert(notice, '<div class="plainlinks">')
             tab.insert('<div class="plainlinks">')
            table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
              .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
         end
         end
         table.insert(notice, 'Les éditeurs peuvent travailler dans le ')
         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
             table.insert(notice, '[[' .. bacasable .. '|bac à sable]]')
             tab.insert('[[' .. bacasable .. '|bac à sable]]')
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(notice, argbacasable:fullUrl('action=edit'))
              .insert(argbacasable:fullUrl('action=edit'))
            table.insert(notice, ' modifier])</span>')
              .insert(' modifier])</span>')
         else
         else
             table.insert(notice, 'bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
             tab.insert('bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(notice, argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
              .insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
            table.insert(notice, ' créer])</span>')
              .insert(' créer])</span>')
         end
         end
         table.insert(notice, ' et la page de ')
         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
             table.insert(notice, '[[' .. test .. '|test]]')
             tab.insert('[[' .. test .. '|test]]')
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(notice, argtest:fullUrl('action=edit'))
              .insert(argtest:fullUrl('action=edit'))
            table.insert(notice, ' modifier])</span>')
              .insert(' modifier])</span>')
         else
         else
             table.insert(notice, 'test&nbsp;<span style="font-size:89%; font-style:normal;">([')
             tab.insert('test&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(notice, argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
              .insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
            table.insert(notice, ' créer])</span>')
              .insert(' créer])</span>')
         end
         end
 
         table.insert(notice, '.<br />Veuillez placer les catégories dans la sous-page ')
         tab.insert('.<br />Veuillez placer les catégories dans la sous-page ')
        table.insert(notice, '<span class="plainlinks">[')
          .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
             table.insert(notice, arg:fullUrl('action=edit'))
             tab.insert(arg:fullUrl('action=edit'))
         else
         else
             table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
             tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
         end
         end
        tab.insert(' /Documentation].')
    end
    tab.insert('</p></div></div>')


        table.insert(notice, ' /Documentation].')
     return tab.concat()
    end
    table.insert(notice, '</p></div></div>')
     return table.concat(notice)
end
end


return p
return p

Version du 2 octobre 2013 à 08:30

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

--Ce module implémente le modèle {{Documentation}}.
 
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('<div style="clear:both />')
           .insert(frame:preprocess('{{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('<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:')

    if not args.couleur then tab.insert('#ecfcf4')
    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%">&nbsp;')

    if args.titre then tab.insert(args.titre)
    else tab.insert('Documentation') end
    tab.insert('</span>')
 
	tab.insert('<span class="mw-editsection plainlinks">&#91;[')
	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(']&#93;&#32;&#91;[')
    end
    tab.insert(page:fullUrl('action=purge') .. ' purger]')
       .insert('&#93;</span></div>')

    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('<nowiki />'))
           .insert('\n')
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            tab.insert(frame:preprocess('{{' .. arg .. '}}'))
        end
    end
    tab.insert('\n')
       .insert(frame:preprocess('<nowiki />'))
       .insert('<div style="clear:both" />\n')

    return tab.concat()
end
 
function p.notice(page)
    local arg = mw.title.new(args[1] or doc)
 
    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
            tab.insert(args.notice)
        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
    else
        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('&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(arg:fullUrl('action=edit'))
               .insert(' modifier]&nbsp;|&nbsp;[')
               .insert(arg:fullUrl('action=history') .. ' historique])</span>.<br />')
        else
            tab.insert('<div class="plainlinks">')
               .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
        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('[[' .. bacasable .. '|bac à sable]]')
               .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argbacasable:fullUrl('action=edit'))
               .insert(' modifier])</span>')
        else
            tab.insert('bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
               .insert(' créer])</span>')
        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 .. '|test]]')
               .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argtest:fullUrl('action=edit'))
               .insert(' modifier])</span>')
        else
            tab.insert('test&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
               .insert(' créer])</span>')
        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
            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('</p></div></div>')

    return tab.concat()
end

return p