Модул:Testcase rows
Документацију овог модула можете да направите на страници Модул:Testcase rows/док
-- This module generates a table of test cases. Each test case is for a
-- different template called with the same parameters. The test cases are
-- displayed vertically, with one template on each row.
--
-- All parameters passed to the module are passed through to the templates,
-- with the exception of parameters starting with an underscore character
-- ("_"), which are reserved for internal use.
local mTableTools = require('Module:TableTools')
local p = {}
function p._main(args, frame)
frame = frame or mw.getCurrentFrame()
local basePageTitle = mw.title.getCurrentTitle().basePageTitle
-- Find the template arguments.
local targs = {}
for k, v in pairs(args) do
if type(k) ~= 'string' or not k:find('^_') then
targs[k] = v
end
end
-- Find the templates to work on.
if not args._template1 then
args._template1 = args._template
end
if not args._template1 then
args._template1 = basePageTitle.text
end
if not args._template2 then
args._template2 = args._template1 .. '/sandbox'
end
local templateNums = mTableTools.affixNums(args, '_template')
-- Build the HTML table.
local root = mw.html.create('table')
root
:addClass(args._class)
:cssText(args._style)
if args._caption then
root
:tag('caption')
:wikitext(args._caption)
end
for _, num in ipairs(templateNums) do
-- Get the display values
local template = args['_template' .. tostring(num)]
local success, output = pcall(
frame.expandTemplate,
frame,
{title = template, args = targs}
)
if not success or not output then
output = ''
end
local heading = args['_heading' .. tostring(num)] or string.format(
'{{[[Template:%s|%s]]}}',
template,
template
)
-- Build the row HTML
root
:tag('tr')
:tag('td')
:css{['text-align'] = 'center', ['font-weight'] = 'bold'}
:wikitext(heading)
:done()
:done()
:tag('tr')
:tag('td')
:newline()
:wikitext(output)
end
return tostring(root)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Testcase rows',
valueFunc = function (k, v)
if type(k) == 'string' and k:find('^_') then
v = mw.text.trim(v)
if v ~= '' then
return v
end
else
return v
end
end
})
return p._main(args, frame)
end
return p