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

De wikarphy
Linarphy (discussion | contributions)
Aucun résumé des modifications
Linarphy (discussion | contributions)
Aucun résumé des modifications
Ligne 25 : Ligne 25 :


function p:main(frame)
function p:main(frame)
     local script = Script:new(frame.args[1], frame.args[2])
     if frame.args then
    return script:build()
        local script = Script:new(frame.args[1], frame.args[2])
        return script:build()
    else
        return "Args does not exist"
    end
end
end


return p
return p

Version du 5 mars 2025 à 00:47

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

local Script = {}
local String = require('Module:String')
local p = {}

function Script:new(template, arguments)
    self.__index = self
    self.template = template
    self.arguments = arguments

    return self
end

function Script:build()
    local root = mw.html.create()
    local command = self.template
    for key, value in pairs(self.arguments) do
        if value ~= nil then
            command = String:replace(frame:newChild{title = "module invocation", args = {source = command, pattern = "{" .. key .. "}", replace = value}})
         end
    end
    root:wikitext(command)

    return tostring(root)
end

function p:main(frame)
    if frame.args then
        local script = Script:new(frame.args[1], frame.args[2])
        return script:build()
    else
        return "Args does not exist"
    end
end

return p