Jump to content

Module:Template test case: Difference between revisions

add TestCase:renderColumns and some more supporting methods
(if the first template is specified but the second is not, make the second the sandbox of the first rather than the sandbox of the base page; simplify the title-getting code in the process)
(add TestCase:renderColumns and some more supporting methods)
Line 20: Line 20:
-- Set input
-- Set input
for k, v in pairs(options or {}) do
for k, v in pairs(options or {}) do
obj[k] = v
if not Template[k] then
obj[k] = v
end
end
end
obj.invocation = invocationObj
obj.invocation = invocationObj
Line 69: Line 71:
local link = self:makeLink(display)
local link = self:makeLink(display)
return mw.text.nowiki('{{') .. link .. mw.text.nowiki('}}')
return mw.text.nowiki('{{') .. link .. mw.text.nowiki('}}')
end
function Template:makeHeading()
return self.heading or self:makeBraceLink()
end
end


Line 144: Line 150:


return obj
return obj
end
function TestCase:getTemplateOutput(templateObj)
local output = templateObj:getOutput()
if self.options.resetRefs then
mw.getCurrentFrame():extensionTag('references')
end
return output
end
function TestCase:renderColumns()
local root = mw.html.create('table')
root
:addClass(self.options.class)
:cssText(self.options.style)
:tag('caption')
:wikitext(self.options.caption or 'Side by side comparison')
-- Headings
local headingRow = root:tag('tr')
if self.options.rowheader then
headingRow:tag('th'):wikitext(self.options.heading0)
end
local width = tostring(math.floor(100 / #self.templates)) .. '%'
for i, obj in ipairs(self.templates) do
headingRow
:tag('th')
:css('width', width)
:wikitext(obj:makeHeading())
end
-- Row header
local dataRow = root:tag('tr'):css('vertical-align', 'top')
if self.options.rowheader then
dataRow:tag('th')
:attr('scope', 'row')
:wikitext(self.options.rowheader)
end
-- Template output
for i, obj in ipairs(self.templates) do
dataRow:tag('td')
:newline()
:wikitext(self:getTemplateOutput(obj))
:wikitext(self.options.after)
end
return tostring(root)
end
end


Line 152: Line 206:
ret[#ret + 1] = '<div style="clear: both;"></div>'
ret[#ret + 1] = '<div style="clear: both;"></div>'
ret[#ret + 1] = obj:makeBraceLink()
ret[#ret + 1] = obj:makeBraceLink()
ret[#ret + 1] = obj:getOutput()
ret[#ret + 1] = self:getTemplateOutput(obj)
end
end
return table.concat(ret, '\n\n')
return table.concat(ret, '\n\n')
Cookies help us deliver our services. By using our services, you agree to our use of cookies.