« 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 |
||
Ligne 3 : | Ligne 3 : | ||
local p = {} | local p = {} | ||
function Script:new( | function Script:new(frame) | ||
self.__index = self | self.__index = self | ||
self.template = | self.template = frame.args[1] | ||
self.arguments = | self.arguments = frame.args[2] | ||
return self | |||
end | end | ||
Ligne 13 : | Ligne 15 : | ||
local command = self.template | local command = self.template | ||
for key, value in pairs(self.arguments) do | for key, value in pairs(self.arguments) do | ||
command = String:replace(command, "{" .. key .. "}", value) | if value ~= nil then | ||
command = String:replace({ test = 1, args = { source = command, pattern = "{" .. key .. "}", replace = value } }) | |||
end | |||
end | end | ||
root:wikitext(command) | root:wikitext(command) | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
function p:main(frame) | function p:main(frame) | ||
local script = Script:new(frame | local script = Script:new(frame) | ||
return script:build() | return script:build() | ||
end | end | ||
return p | return p |
Version du 4 mars 2025 à 03:26
La documentation pour ce module peut être créée à Module:Script/doc
local Script = {}
local String = require('Module:String')
local p = {}
function Script:new(frame)
self.__index = self
self.template = frame.args[1]
self.arguments = frame.args[2]
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({ test = 1, args = { source = command, pattern = "{" .. key .. "}", replace = value } })
end
end
root:wikitext(command)
return tostring(root)
end
function p:main(frame)
local script = Script:new(frame)
return script:build()
end
return p