Module:Call wikitext
Appearance
Implements {{Call wikitext}}. This module was originally designed for providing an effective way to create testcases for Module:ArgRest, by "mocking" a transcluded template.
Usage
This module can also be used directly. See Template:Call wikitext/doc for documentation and replace {{Call wikitext
with {{#invoke:Call wikitext|main
. For example:
{{Call wikitext|sourceCode=<nowiki>{{{foo}}}</nowiki>|foo=Hello!}}
→ Lua error at line 5: sourceCode arg not provided.
{{#invoke:Call wikitext|main|sourceCode=<nowiki>{{{foo}}}</nowiki>|foo=Hello!}}
→ Hello!
require('strict')
local p = {}
function p.main(frame)
local code = frame.args['sourceCode'] or error("sourceCode arg not provided")
if code:match'nowiki' then -- undo nowiki sanitization
code = mw.text.unstripNoWiki(code)
else
error("sourceCode arg was missing <nowiki>")
end
-- Unsanitize < and >
code = code:gsub("<", "<"):gsub(">", ">")
-- Remove sourceCode from the arguments
local newArgs = {}
for k, v in pairs(frame.args) do
if k ~= 'sourceCode' then
newArgs[k] = v
end
end
-- Create a new frame without "sourceCode"
local newFrame = frame:getParent():newChild{
title = "Module:Example",
args = newArgs
}
return newFrame:preprocess(code)
end
return p