Module:Call wikitext: Difference between revisions
Appearance
Content deleted Content added
m Lemondoge moved page Module:Sandbox/Lemondoge/SpoofTemplate to Module:ArgRest/testCaser without leaving a redirect: Module is intended exclusively to allow argRest to be tested in a /testcases page |
BrandonXLF (talk | contribs) Remove sourceCode from the arguments before preprocessing |
||
Line 1: | Line 1: | ||
require('strict') |
|||
p = {} |
local p = {} |
||
function p.main(frame) |
function p.main(frame) |
||
local code = frame.args['sourceCode'] or error("sourceCode arg not provided") |
local code = frame.args['sourceCode'] or error("sourceCode arg not provided") |
||
if code:match'nowiki' then -- undo nowiki sanitization |
if code:match'nowiki' then -- undo nowiki sanitization |
||
code = mw.text.unstripNoWiki(code) |
code = mw.text.unstripNoWiki(code) |
||
else |
|||
error("sourceCode arg was missing <nowiki>") |
|||
⚫ | |||
end |
|||
-- Unsanitize < and > |
|||
⚫ | |||
-- 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 |
end |
||
Revision as of 18:28, 1 September 2024
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