« Module:Documentation » et « Module:TableBuilder » : différence entre les pages

De Sarkarverse
(Différence entre les pages)
Aller à la navigation Aller à la recherche
imported>T12
m (1 version)
 
imported>T12
m (1 version)
 
Ligne 1 : Ligne 1 :
--Ce module implémente le modèle {{Documentation}}.
--Module appliquant aux fonctions de la librairie Table une inteface fluide.
local p = {}


local TableBuilder = require('Module:TableBuilder')
local meta = {
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
     insert = function ( t, ... )
    if page.subpageText == 'Bac à sable' then
         table.insert( t, ... )
         tab.insert('<div style="clear:both />')
        return t
          .insert(frame:preprocess('{{Sous-page de bac à sable}}'))
     end,
     end
      
     remove = function ( t, ... )
     --Génération de la documentation
        table.remove( t, ... )
     p.entete(page)
        return t
    p.contenu(frame, page)
     end,
    p.notice(page)
      
 
     sort = function ( t, ... )
    return tab.concat()
         table.sort( t, ... )
end
         return t
     end,
function p.docname(page)
   
    --On n'est pas dans une sous-page
    maxn = function ( t )
     if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
        return table.maxn( t )
     end,
     --On est dans une sous-page
   
     if page.subpageText == 'Documentation'
    concat = function ( t, ... )
    or page.subpageText == 'Bac à sable'
        return table.concat( t, ... )
    or page.subpageText == 'Test' then
     end,
         return page.subjectNsText .. ":" .. page.baseText .. "/Documentation"
   
    else
     minsert = function( t, ... )
         return page.subjectNsText .. ":" .. page.text .. "/Documentation"
        local sel
     end
        for i = 1, select( '#', ... ) do
end
            sel = select( i, ... )
            if sel then
function p.ifexist(page)
                table.insert( t, sel )
    if not page or not mw.title.new(page).exists then return false end
            end
     return true
        end
end
        return t
     end,
function p.entete(page)
      
    tab.insert('<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:')
    tinsert = function( t, tab, first, last )
 
        if type( tab ) == 'table' then
    if not args.couleur then tab.insert('#ecfcf4')
            for i = ( tonumber( first ) or 1 ), ( tonumber( last ) or #tab ) do
     else tab.insert(args.couleur) end
                table.insert( t, tab[i] )
            end
     tab.insert('; padding:1em 1em 0.8em;">')
        end
      .insert('<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
        return t
      .insert('[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
    end,
      .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>')
 
if not args.contenu then
        local arg = mw.title.new(args[1] or doc)
        tab.insert('<span class="mw-editsection plainlinks">&#91;[')


        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
meta.__index = function ( t, key )  
            tab.insert(arg:fullUrl('action=edit'))
    local metafunc = meta[key]
              .insert(' modifier')
    if type( metafunc ) == 'function' then
        else
         return function ( ... ) return metafunc( t, ... ) end
            tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
              .insert(' créer')
         end
        tab.insert(']&#93;&#32;&#91;[')
        tab.insert(page:fullUrl('action=purge') .. ' purger]')
          .insert('&#93;</span>')
     end
     end
tab.insert('</div>')
    return tab.concat()
end
end
       
function p.contenu(frame, page)
-- fin des fonctions de la meta-table
    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()
local TableBuilder = {
end
     new = function( ... )
         local t = { ... }
function p.notice(page)
         setmetatable( t, meta )
     local arg = mw.title.new(args[1] or doc)
        return t
    end,
    if args.contenu then
   
        tab.insert('<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
    set = function( t )
          .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n')
        if type( t ) == 'table' then
            setmetatable( t, meta )
         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. [')
              .insert(page:fullUrl('action=purge'))
  .insert(' Cliquez ici pour purger le cache].')
              .insert('<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
         return t
         if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
    end,
            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
    clone = function ( t )
             tab.insert('[[' .. bacasable .. '|bac à sable]]')
         local tableRefs = { }
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
        local function recursiveClone( val )
              .insert(argbacasable:fullUrl('action=edit'))
             if type( val ) == 'table' then
              .insert(' modifier])</span>')
                -- Encode circular references correctly
        else
                if tableRefs[val] ~= nil then
            tab.insert('bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
                    return tableRefs[val]
              .insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
                end
              .insert(' créer])</span>')
   
                local retVal = { }
                tableRefs[val] = setmetatable( retVal, meta )
   
                for key, elt in pairs( val ) do
                    retVal[key] = recursiveClone( elt )
                end
                return retVal
            else
                return val
            end
         end
         end
         tab.insert(' et la page de ')
         return recursiveClone( t )
    end,
        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
return TableBuilder

Version actuelle datée du 16 décembre 2013 à 05:48

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

--Module appliquant aux fonctions de la librairie Table une inteface fluide.

local meta = {

    insert = function ( t, ... )
        table.insert( t, ... )
        return t
    end,
    
    remove = function ( t, ... )
        table.remove( t, ... )
        return t
    end,
    
    sort = function ( t, ... )
        table.sort( t, ... )
        return t
    end,
    
    maxn = function ( t )
        return table.maxn( t )
    end,
    
    concat = function ( t, ... )
        return table.concat( t, ... )
    end,
    
    minsert = function( t, ... )
        local sel
        for i = 1, select( '#', ... ) do
            sel = select( i, ... )
            if sel then
                table.insert( t, sel )
            end
        end
        return t
    end,
    
    tinsert = function( t, tab, first, last )
        if type( tab ) == 'table' then
            for i = ( tonumber( first ) or 1 ), ( tonumber( last ) or #tab ) do
                table.insert( t, tab[i] )
            end
        end
        return t
    end,
}   

meta.__index = function ( t, key ) 
    local metafunc = meta[key]
    if type( metafunc ) == 'function' then
        return function ( ... ) return metafunc( t, ... ) end
    end
end
        
-- fin des fonctions de la meta-table


local TableBuilder = {
    new = function( ... )
        local t = { ... }
        setmetatable( t, meta )
        return t
    end,
    
    set = function( t )
        if type( t ) == 'table' then
            setmetatable( t, meta )
        end
        return t
    end,

    clone = function ( t )
        local tableRefs = { }
        local function recursiveClone( val )
            if type( val ) == 'table' then
                -- Encode circular references correctly
                if tableRefs[val] ~= nil then
                    return tableRefs[val]
                end
    
                local retVal = { }
                tableRefs[val] = setmetatable( retVal, meta )
    
                for key, elt in pairs( val ) do
                    retVal[key] = recursiveClone( elt )
                end
                return retVal
            else
                return val
            end
        end
        return recursiveClone( t )
    end,
}

return TableBuilder