« Module:Script » : différence entre les versions
Page créée avec « local Script = {} local String = require('Module:String') local p = {} function Script:new(template, arguments) self.__index = self self.template = template self.arguments = arguments end function Script:build() local root = mw.html.create() local command = self.template for key, value in pairs(self.arguments) do command = String:replace(command, "{" .. key .. "}", value) end root:wikitext(command) return tostring(ro... » |
Aucun résumé des modifications |
||
(13 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 7 : | Ligne 7 : | ||
self.template = template | self.template = template | ||
self.arguments = arguments | self.arguments = arguments | ||
return self | |||
end | end | ||
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 | ||
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 | |||
end | end | ||
root:wikitext(command) | root:wikitext(command) | ||
return tostring(root) | root:wikitext("</syntaxhighlight>") | ||
return mw:getCurrentFrame():preprocess(tostring(root)) | |||
end | end | ||
function p | function p.main(frame) | ||
local script = Script:new(frame.args[1], frame.args[2]) | local script = Script:new(frame.args[1], frame.args[2]) | ||
return script:build() | return script:build() |
Dernière version du 5 mars 2025 à 02:12
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()
root:wikitext("<syntaxhighlight lang=\"bash\">")
local command = self.template
if self.arguments then
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
end
root:wikitext(command)
root:wikitext("</syntaxhighlight>")
return mw:getCurrentFrame():preprocess(tostring(root))
end
function p.main(frame)
local script = Script:new(frame.args[1], frame.args[2])
return script:build()
end
return p