Jump to content

Module:RfX template maker

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 00:13, 10 February 2014 (new version for use with data table). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module allows people to make templates that display data about current RfA and RfB discussions,
-- without them having to know how to program in Lua.

local data = require('Module:RfX template maker/data')

local p = {}

local function err(msg)
	return string.format('<strong class="error">Error: %s.</strong>', msg)
end

function p.main(frame)
	local args = frame.args
	local template = args.template
	if not template then
		return err('template not specified')
	end

	local rfas = data.rfa
	local rfbs = data.rfb
	
	local rfxTable
	if args.type == 'rfa' then
		rfxTable = rfas
	elseif args.type == 'rfb' then
		rfxTable = rfbs
	else
		return err('type parameter must be "rfa" or "rfb"')
	end

	local ret = {}
	local renderRow = p.renderRow
	for _, t in ipairs(rfxTable) do
		local targs = {}
		for k, v in pairs(t) do
			targs[k] = v
		end
		ret[#ret + 1] = frame:expandTemplate{title = template, args = targs}
	end
	return table.concat(ret, '\n')
end

function p.rfacount()
	local rfas = data.rfa
	if rfas then
		return #rfas
	else
		return 0
	end
end

function p.rfbcount()
	local rfbs = data.rfb
	if rfbs then
		return #rfbs
	else
		return 0
	end
end

return p