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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
appel redondant de p.docname()
0x010D (discussion | contributions)
preprocess de preprocess, intéressant...
Ligne 15 : Ligne 15 :


     --Génération de la documentation
     --Génération de la documentation
     table.insert(corps, frame:preprocess(p.entete(frame, args, page)))
     table.insert(corps, frame:preprocess(p.entete(args, page)))
     table.insert(corps, p.contenu(frame, args, page))
     table.insert(corps, p.contenu(frame, args, page))
     table.insert(corps, frame:preprocess(p.notice(frame, args, page)))
     table.insert(corps, frame:preprocess(p.notice(args, page)))


     --Code HTML brut
     --Code HTML brut
Ligne 48 : Ligne 48 :
end
end


function p.entete(frame, args, page)
function p.entete(args, page)
     local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
     local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
     local doc = p.docname(page)
     local doc = p.docname(page)
Ligne 123 : Ligne 123 :
end
end


function p.notice(frame, args, page)
function p.notice(args, page)
     local notice = {}
     local notice = {}
     local doc = p.docname(page)
     local doc = p.docname(page)
Ligne 172 : Ligne 172 :
         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('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}')
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../Bac à sable}}')) then
         or p.ifexist('{{#rel2abs:' .. doc .. '/../Bac à sable}}') then
             table.insert(notice, '[[{{#rel2abs:')
             table.insert(notice, '[[{{#rel2abs:')
             if args[1] then
             if args[1] then
Ligne 202 : Ligne 202 :
         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('{{#rel2abs:' .. args[1] .. '/../Test}}')
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../Test}}')) then
         or p.ifexist('{{#rel2abs:' .. doc .. '/../Test}}') then
             table.insert(notice, '[[{{#rel2abs:')
             table.insert(notice, '[[{{#rel2abs:')
             if args[1] then
             if args[1] then

Version du 23 juillet 2013 à 13:46

--Ce module implemente le modèle Modèle:Méta documentation de modèle.

local p = {}

function p.corps(frame)

   local args = frame:getParent().args
   local page = mw.title.getCurrentTitle()
   local corps = {}
   --Bandeau pour les sous-pages /Bac à sable
   if page.subpageText == 'Bac à sable' then

table.insert(corps, '

')
       table.insert(corps, frame:preprocess('Modèle:Sous-page de bac à sable'))
   end
   --Génération de la documentation
   table.insert(corps, frame:preprocess(p.entete(args, page)))
   table.insert(corps, p.contenu(frame, args, page))
   table.insert(corps, frame:preprocess(p.notice(args, page)))
   --Code HTML brut
   if args.raw then
       return frame:preprocess('' .. table.concat(corps) .. '')
   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(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.entete(args, page)

local entete = {'
') table.insert(entete, '
')
   table.insert(entete, 'Documentation du modèle')
   table.insert(entete, ' ')
   if args.titre then
       table.insert(entete, args.titre)
   else
       table.insert(entete, 'Documentation')
   end
   table.insert(entete, '')
   if not args.contenu then
       table.insert(entete, '[[')
       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}}]] [Modèle:Purger le cache')
           else
               table.insert(entete, args[1])
               table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
           end
       else
           if p.ifexist(doc) then
               table.insert(entete, doc)
               table.insert(entete, '|action=edit modifier}}]] [Modèle:Purger le cache')
           else
               table.insert(entete, doc)
               table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
           end
       end
       table.insert(entete, ']')
   end
table.insert(entete, '
')
   return table.concat(entete)

end

function p.contenu(frame, args, page)

   local contenu = {}
   local doc = p.docname(page)
   if args.contenu then
       table.insert(contenu, '\n')
       table.insert(contenu, args.contenu)
   else
       table.insert(contenu, frame:preprocess('\n'))
       --Évite toute récursion
       if args[1]
       and frame:preprocess('Module:Documentation') ~= frame:preprocess()
       and p.ifexist(args[1]) then
           table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
       elseif frame:preprocess('Module:Documentation') ~= frame:preprocess('%27_.._doc_.._%27')
       and p.ifexist(doc) then
           table.insert(contenu, frame:preprocess('Modèle:' .. doc .. ''))
       end
   end
table.insert(contenu, frame:preprocess('\n
\n'))
   return table.concat(contenu)

end

function p.notice(args, page)

   local notice = {}
   local doc = p.docname(page)
   if args.contenu then
table.insert(notice, '