Jump to content

Module:IPAc-en/documentation

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 02:48, 19 June 2015 (start documentation module for Module:IPAc-en). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module generates automatic documentation for [[Template:IPAc-en]].

local data = mw.loadData('Module:IPAc-en/data')
local p = {}

local function buildTable(options)
	local ret = {}
	ret[#ret + 1] = '{|' .. (options.class and (' class="' .. options.class .. '') or '')
	if options.headerRow then
		for i, header in ipairs(options.headerRow) do
			ret[#ret + 1] = '! ' .. header
		end
	end
	if options.rows then
		for i, t in ipairs(options.rows) do
			ret[#ret + 1] = '|-'
			for j, data in ipairs(t) do
				ret[#ret + 1] = '| ' .. data
			end
		end
	end
	ret[#ret + 1] = '|}'
	return table.concat(ret, '\n')
end

function p.pronunciation()
	local rows = {}
	for code, t in pairs(data.pronunciation) do
		rows[#rows + 1] = {code, t.text}
	end
	table.sort(rows, function (t1, t2)
		return t1[1] < t2[1]
	end)
	return buildTable{
		class = 'wikitable',
		headers = {'Code', 'Output'},
		rows = rows
	}
end

return p