You can edit almost every page by Creating an account and confirming your email.

Module:Testcase rows

From EverybodyWiki Bios & Wiki

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.

It implements the {{testcase rows}} template.

Usage from wikitext

Normally this module should be used via the {{testcase rows}} template, although if you want to it is possible to call the module directly using the syntax {{#invoke:Testcase rows|main|args}}. See the template documentation for a list of parameters.

Usage from Lua modules

To use this module from other Lua modules, first load the module.

local mTestcaseRows = require('Module:Testcase rows')

You can then generate the test-case table by using the _main function.

mTestcaseRows._main(args)

The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{testcase rows}} template documentation.


Example

The module produces output like this:

{{#invoke:Testcase rows|main
| _template = ombox
| image = [[File:Bad Title Example.png|40px]]
| imageright = [[File:Bad Title Example.png|40px]]
| text = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tristique sagittis cursus. Cras nibh elit, consectetur sed semper sollicitudin, lobortis nec elit. Morbi vitae neque non diam commodo faucibus. Phasellus volutpat diam orci. Praesent tempor scelerisque dapibus. Duis consectetur eros ut elit semper rutrum.
}}
{{ombox}}
{{ombox/sandbox}}

-- 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

This module "Testcase rows" is from Wikipedia if otherwise notified