Module:$var
Template:Shared Template Warning
File:Greek lc alpha icon.svg | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Lua module for rendering the source of template transclusions using Template:Mono.
Usage
{{#invoke:$var|$var_name}}
[[Category:Modules{{#translation:}}]]
-- <nowiki>
--------------------------------------------------------------------------------
-- Lua module for rendering the source of template transclusions using
-- [[mw:Special:MyLanguage/Help:Extension:Translate/Page translation administration#Variables|$<var>var</var>]].
--
-- @module $var
-- @alias p
-- @author [[User:ExE Boss]]
-- @require [[Module:Arguments]]
--------------------------------------------------------------------------------
require("strict")
local getArgs = require("Module:Arguments").getArgs
local function echoSource(name, args)
local content = mw.html.create()
local unnamed = {}
content:wikitext("{{", name)
for i, v in ipairs(args) do
unnamed[i] = true -- unnamed arguments can have leading and trailing whitespace
content:wikitext("|", v) -- XXX: escaped "|" and "=" as "{{!}}" and "{{=}}"?
end
for k, v in pairs(args) do
if not unnamed[k] then
content:wikitext("|", k, "=", v) -- XXX: escaped "|" as "{{!}}"?
end
end
content:wikitext("}}")
return tostring(mw.html.create("code"):wikitext(mw.text.nowiki(tostring(content:allDone()))):allDone())
end
local mt = {}
function mt.__index(t, name)
if type(name) == "string" and mw.ustring.find(name, "^%$.") then
return function(frame)
local args = getArgs(frame, {
trim = false,
removeBlanks = false,
wrappers = {
"Template:$1",
"Template:$2",
"Template:$3",
"Template:$4",
"Template:$5",
"Template:$6",
"Template:$7",
"Template:$8",
"Template:$9",
},
})
return echoSource(name, args)
end
end
end
return setmetatable({}, mt)