Jump to content

Please don't skip this 1-minute read. Festipedia is hosted by the FR Heritage Group, a registered charity (No. 1199296). Festipedia is, and always will be, free. But we need your support to keep Festipedia running and to help fund heritage projects. Any donation you can give will be much appreciated, whether it is £2 or £200.

To make a donation, please go to our website, click the Add to Cart button next to General Donation, change the quantity to the amount you want to donate and click the checkout button. Thank you for your support.

Module:Separated entries

From Festipedia, hosted by the FR Heritage Group

-- This module takes positional parameters as input and concatenates them with
-- an optional separator. The final separator (the "conjunction") can be
-- specified independently, enabling natural-language lists like
-- "foo, bar, baz and qux".

local compressSparseArray = require('Module:TableTools').compressSparseArray
local p = {}

function p._main(args)
	local separator = args.separator
		-- Decode (convert to Unicode) HTML escape sequences, such as " " for space.
		and mw.text.decode(args.separator) or ''
	local conjunction = args.conjunction and mw.text.decode(args.conjunction) or separator
	-- Discard named parameters.
	local values = compressSparseArray(args)
	return mw.text.listToText(values, separator, conjunction)
end

local function makeInvokeFunction(separator, conjunction)
	return function (frame)
		local args = require('Module:Arguments').getArgs(frame)
		args.separator = separator or args.separator
		args.conjunction = conjunction or args.conjunction
		return p._main(args)
	end
end

p.main = makeInvokeFunction()
p.br = makeInvokeFunction('<br />')
p.comma = makeInvokeFunction(mw.message.new('comma-separator'):plain())

return p