Jump to content

Module:Template test case: Difference between revisions

In the end they could be merged nicely
(renderTableRows: use class and style parameters)
(In the end they could be merged nicely)
Line 175: Line 175:
columns = 'renderColumns',
columns = 'renderColumns',
rows = 'renderRows',
rows = 'renderRows',
tablerows = 'renderTableRows',
tablerows = 'renderRows',
inline = 'renderInline',
inline = 'renderInline',
default = 'renderDefault'
default = 'renderDefault'
Line 434: Line 434:


for _, obj in ipairs(self.templates) do
for _, obj in ipairs(self.templates) do
-- Build the row HTML
if self.options.showheader then
tableroot:tag('tr'):tag('td')
:css('text-align', 'center')
:css('font-weight', 'bold')
:wikitext(obj:makeHeader())
end
tableroot:tag('tr'):tag('td')
:newline()
:wikitext(self:getTemplateOutput(obj))
end
return tostring(root)
end
function TestCase:renderTableRows()
local root = mw.html.create()
if self.options.showcode then
root
:wikitext(self.templates[1]:getInvocation())
:newline()
end
local tableroot = root:tag('table')
tableroot
:addClass(self.options.class)
:cssText(self.options.style)
for i, obj in ipairs(self.templates) do
local dataRow = tableroot:tag('tr')
local dataRow = tableroot:tag('tr')
-- Row header
if self.options.showheader then
if self.options.showheader then
dataRow:tag('th')
if self.options.format == 'tablerows' then
:attr('scope', 'row')
dataRow:tag('th')
:css('text-align', 'left')
:attr('scope', 'row')
:wikitext(obj:makeHeader())
:css('text-align', 'left')
:wikitext(obj:makeHeader())
dataRow:tag('td')
dataRow:tag('td')
:css('padding', '0 1em')
:css('padding', '0 1em')
:wikitext('')
:wikitext('→')
else
dataRow:tag('td')
:css('text-align', 'center')
:css('font-weight', 'bold')
:wikitext(obj:makeHeader())
dataRow = tableroot:tag('tr')
end
end
end
-- Template output
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
 
return tostring(root)
return tostring(root)
end
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.