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

Aucun résumé des modifications
Aucun résumé des modifications
 
(10 versions intermédiaires par le même utilisateur non affichées)
Ligne 3 : Ligne 3 :
local p = {}
local p = {}


function Script:new(frame)
function Script:new(template, arguments)
     self.__index = self
     self.__index = self
     self.template = frame.args[1]
     self.template = template
     self.arguments = frame.args[2]
     self.arguments = arguments


     return self
     return self
Ligne 13 : Ligne 13 :
function Script:build()
function Script:build()
     local root = mw.html.create()
     local root = mw.html.create()
    root:wikitext("<syntaxhighlight lang=\"bash\">")
     local command = self.template
     local command = self.template
     for key, value in pairs(self.arguments) do
     if self.arguments then
        if value ~= nil then
        for key, value in pairs(self.arguments) do
            command = String:replace(frame:newChild{title = "module invocation", args = {source = command, pattern = "{" .. key .. "}", replace = value}})
            if value ~= nil then
        end
                command = String:replace(frame:newChild{title = "module invocation", args = {source = command, pattern = "{" .. key .. "}", replace = value}})
            end
        end
     end
     end
     root:wikitext(command)
     root:wikitext(command)
 
    root:wikitext("</syntaxhighlight>")
     return tostring(root)
     return mw:getCurrentFrame():preprocess(tostring(root))
end
end


function p:main(frame)
function p.main(frame)
     local script = Script:new(frame)
     local script = Script:new(frame.args[1], frame.args[2])
     return script:build()
     return script:build()
end
end


return p
return p