Module:template: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local export = {} function export.show(frame) frame = frame:getParent() or frame local out = {"{{", frame.args[1]} local i = 2 while frame.args[i] do table.insert(out, "|" .. frame.args[i]) i = i + 1 end for key, value in ipairs(frame.args) do if type(key) == "string" then table.insert(out, "|" .. key .. "=" .. value) end end table.insert("}}") return table.concat(out) end return export") |
No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
function export. | function export.make_template(args, nested) | ||
if not args[1] then error("at least one argument must be given to {{temp}}") end | |||
local out = {"{{" | local out = {(nested and "") or "<code>", "{{[[Template:" .. args[1] .. "|" .. args[1] .. "]]"} | ||
local i = 2 | local i = 2 | ||
while | while args[i] do | ||
table.insert(out, "|" . | table.insert(out, "|" .. args[i]) | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
for key, value in | for key, value in require("Module:table").sortedPairs(args) do | ||
if type(key) == "string" then | if type(key) == "string" then | ||
table.insert(out, "|" .. key .. "=" .. value) | table.insert(out, "|" .. key .. "=" .. value) | ||
end | end | ||
end | end | ||
table.insert("}}") | table.insert(out, "}}" .. ((nested and "") or "</code>")) | ||
return table.concat(out) | return table.concat(out) | ||
end | |||
function export.show(frame) | |||
return export.make_template(frame:getParent().args, false) | |||
end | |||
function export.showNested(frame) | |||
return export.make_template(frame:getParent().args, true) | |||
end | end | ||
return export | return export |
Latest revision as of 14:37, 7 August 2023
Documentation for this module may be created at Module:template/documentation
local export = {}
function export.make_template(args, nested)
if not args[1] then error("at least one argument must be given to {{temp}}") end
local out = {(nested and "") or "<code>", "{{[[Template:" .. args[1] .. "|" .. args[1] .. "]]"}
local i = 2
while args[i] do
table.insert(out, "|" .. args[i])
i = i + 1
end
for key, value in require("Module:table").sortedPairs(args) do
if type(key) == "string" then
table.insert(out, "|" .. key .. "=" .. value)
end
end
table.insert(out, "}}" .. ((nested and "") or "</code>"))
return table.concat(out)
end
function export.show(frame)
return export.make_template(frame:getParent().args, false)
end
function export.showNested(frame)
return export.make_template(frame:getParent().args, true)
end
return export