Module:Template test case and Module:Template test case/sandbox: Difference between pages
Appearance
(Difference between pages)
imported>Deadfire Creation (as this is needed) |
imported>Deadfire creation |
||
| Line 117: | Line 117: | ||
return self.template | return self.template | ||
else | else | ||
return require('Module:Template invocation').name(self.title) | return require('Module:Template invocation/sandbox').name(self.title) | ||
end | end | ||
end | end | ||
| Line 145: | Line 145: | ||
} | } | ||
if format == 'code' then | if format == 'code' then | ||
invocation = '< | invocation = '<syntaxhighlight lang="wikitext" inline>' .. invocation .. '</syntaxhighlight>' | ||
elseif format == 'kbd' then | elseif format == 'kbd' then | ||
invocation = '<kbd>' .. mw.text.nowiki(invocation) .. '</kbd>' | invocation = '<kbd>' .. mw.text.nowiki(invocation) .. '</kbd>' | ||
| Line 352: | Line 352: | ||
:css('border', 'solid silver 1px') | :css('border', 'solid silver 1px') | ||
:css('padding', '0.2em') | :css('padding', '0.2em') | ||
:css('clear', 'both') | |||
:addClass(self.options.notcollapsed == false and 'mw-collapsed' or nil) | :addClass(self.options.notcollapsed == false and 'mw-collapsed' or nil) | ||
if self.options.wantdiff then | if self.options.wantdiff then | ||
| Line 510: | Line 511: | ||
dataRow:tag('td') | dataRow:tag('td') | ||
:newline() | :newline() | ||
:wikitext(self.options.before) | |||
:wikitext(self:getTemplateOutput(obj)) | |||
:wikitext(self.options.after) | |||
:wikitext('<pre style="white-space: pre-wrap;">') | |||
:wikitext(mw.text.nowiki(self.options.before or "")) | |||
:wikitext(mw.text.nowiki(self:getTemplateOutput(obj))) | |||
:wikitext(mw.text.nowiki(self.options.after or "")) | |||
:wikitext('</pre>') | |||
elseif self.options.output == 'nowiki' then | elseif self.options.output == 'nowiki' then | ||
dataRow:tag('td') | dataRow:tag('td') | ||
:newline() | :newline() | ||
:wikitext(mw.text.nowiki(self.options.before or "")) | |||
:wikitext(mw.text.nowiki(self:getTemplateOutput(obj))) | :wikitext(mw.text.nowiki(self:getTemplateOutput(obj))) | ||
:wikitext(mw.text.nowiki(self.options.after or "")) | |||
else | else | ||
dataRow:tag('td') | dataRow:tag('td') | ||
:newline() | :newline() | ||
:wikitext(self.options.before) | |||
:wikitext(self:getTemplateOutput(obj)) | :wikitext(self:getTemplateOutput(obj)) | ||
:wikitext(self.options.after) | |||
end | end | ||
end | end | ||
| Line 541: | Line 550: | ||
end | end | ||
if self.options.output == 'nowiki+' then | if self.options.output == 'nowiki+' then | ||
line[#line + 1] = self.options.before or "" | |||
line[#line + 1] = self:getTemplateOutput(obj) | line[#line + 1] = self:getTemplateOutput(obj) | ||
line[#line + 1] = self.options.after or "" | |||
line[#line + 1] = '<pre style="white-space: pre-wrap;">' | line[#line + 1] = '<pre style="white-space: pre-wrap;">' | ||
line[#line + 1] = mw.text.nowiki(self.options.before or "") | |||
line[#line + 1] = mw.text.nowiki(self:getTemplateOutput(obj)) | line[#line + 1] = mw.text.nowiki(self:getTemplateOutput(obj)) | ||
line[#line + 1] = mw.text.nowiki(self.options.after or "") | |||
line[#line + 1] = '</pre>' | line[#line + 1] = '</pre>' | ||
elseif self.options.output == 'nowiki' then | elseif self.options.output == 'nowiki' then | ||
line[#line + 1] = mw.text.nowiki(self.options.before or "") | |||
line[#line + 1] = mw.text.nowiki(self:getTemplateOutput(obj)) | line[#line + 1] = mw.text.nowiki(self:getTemplateOutput(obj)) | ||
line[#line + 1] = mw.text.nowiki(self.options.after or "") | |||
else | else | ||
line[#line + 1] = self.options.before or "" | |||
line[#line + 1] = self:getTemplateOutput(obj) | line[#line + 1] = self:getTemplateOutput(obj) | ||
line[#line + 1] = self.options.after or "" | |||
end | end | ||
ret[#ret + 1] = table.concat(line) | ret[#ret + 1] = table.concat(line) | ||
| Line 633: | Line 650: | ||
end | end | ||
if self.options.output == 'nowiki+' then | if self.options.output == 'nowiki+' then | ||
ret[#ret + 1] = self:getTemplateOutput(obj) .. | ret[#ret + 1] = (self.options.before or "") .. | ||
self:getTemplateOutput(obj) .. | |||
(self.options.after or "") .. | |||
'<pre style="white-space: pre-wrap;">' .. | '<pre style="white-space: pre-wrap;">' .. | ||
mw.text.nowiki(self:getTemplateOutput(obj)) .. '</pre>' | mw.text.nowiki(self.options.before or "") .. | ||
mw.text.nowiki(self:getTemplateOutput(obj)) .. | |||
mw.text.nowiki(self.options.after or "") .. '</pre>' | |||
elseif self.options.output == 'nowiki' then | elseif self.options.output == 'nowiki' then | ||
ret[#ret + 1] = mw.text.nowiki(self:getTemplateOutput(obj)) | ret[#ret + 1] = mw.text.nowiki(self.options.before or "") .. | ||
mw.text.nowiki(self:getTemplateOutput(obj)) .. | |||
mw.text.nowiki(self.options.after or "") | |||
else | else | ||
ret[#ret + 1] = self:getTemplateOutput(obj) | ret[#ret + 1] = (self.options.before or "") .. | ||
self:getTemplateOutput(obj) .. | |||
(self.options.after or "") | |||
end | end | ||
end | end | ||
| Line 722: | Line 747: | ||
return nowikiObj:getInvocation(options) | return nowikiObj:getInvocation(options) | ||
else | else | ||
return require('Module:Template invocation').invocation( | return require('Module:Template invocation/sandbox').invocation( | ||
options.template, | options.template, | ||
self.invokeArgs | self.invokeArgs | ||
| Line 782: | Line 807: | ||
function bridge.nowiki(args, cfg) | function bridge.nowiki(args, cfg) | ||
cfg = cfg or mw.loadData(DATA_MODULE) | cfg = cfg or mw.loadData(DATA_MODULE) | ||
-- Convert args beginning with _ for consistency with the normal bridge | |||
local newArgs = {} | |||
for k, v in pairs(args) do | |||
local normalName = type(k) == "string" and string.match(k, "^_(.*)$") | |||
if normalName then | |||
newArgs[normalName] = v | |||
else | |||
newArgs[k] = v | |||
end | |||
end | |||
local code = | local code = newArgs.code or newArgs[1] | ||
local invocationObj = NowikiInvocation.new(code, cfg) | local invocationObj = NowikiInvocation.new(code, cfg) | ||
newArgs.code = nil | |||
newArgs[1] = nil | |||
-- Assume we want to see the code as we already passed it in. | -- Assume we want to see the code as we already passed it in. | ||
newArgs.showcode = newArgs.showcode or true | |||
local testCaseObj = TestCase.new(invocationObj, | local testCaseObj = TestCase.new(invocationObj, newArgs, cfg) | ||
return tostring(testCaseObj) | return tostring(testCaseObj) | ||
end | end | ||