Jump to content

Module:Political party/testtable: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
temporary removal of "unsortable" for a check of something in those fields
small cleanup
Line 5: Line 5:
-- Initialise and populate variables
-- Initialise and populate variables
local args = frame.args
local args = frame.args
local index = args['letter']
local index = args.letter
-- Load data from submodule
-- Load data from submodule
Line 16: Line 16:
:wikitext(t)
:wikitext(t)
res:tag('td')
res:tag('td')
:css('background', c['color'])
:css('background-color', c.color)
:wikitext(c['color'])
:wikitext(c['color'])
res:tag('td')
res:tag('td')
:wikitext(c['abbrev'])
:wikitext(c.abbrev)
res:tag('td')
res:tag('td')
:wikitext(c['shortname'])
:wikitext(c.shortname)
return tostring(res)
return tostring(res)
end
end
Line 28: Line 28:
local root = mw.html.create('table')
local root = mw.html.create('table')
root:addClass('wikitable sortable')
root:addClass('wikitable sortable')
:css('background', 'transparent')
:css('background-color', 'transparent')
:css('font-size', '90%')
:css('font-size', '90%')
:css('line-height', '100%')
:css('line-height', '100%')

Revision as of 10:48, 19 November 2021

local p = {}

-- Example of having all the data - color and names - in one table. Requires one page to be edited instead of two when adding a new party.
function p.tables(frame)
	-- Initialise and populate variables
	local args = frame.args
	local index = args.letter
	
	-- Load data from submodule
	local data = mw.loadData('Module:Political party/' .. index)

	-- helper function
	local function table_row(t, c)
		local res = mw.html.create('')
		res:tag('td')
			:wikitext(t)
		res:tag('td')
			:css('background-color', c.color)
			:wikitext(c['color'])
		res:tag('td')
			:wikitext(c.abbrev)
		res:tag('td')
			:wikitext(c.shortname)
		return tostring(res)
	end

	-- build table
	local root = mw.html.create('table')
	root:addClass('wikitable sortable')
		:css('background-color', 'transparent')
		:css('font-size', '90%')
		:css('line-height', '100%')
		:cssText(style)
	local row = root:tag('tr')
	row:tag('th')
		:wikitext('Political party name')
	row:tag('th')
		:addClass('unsortable')
		:wikitext('color')
	row:tag('th')
		:wikitext('abbrev')
	row:tag('th')
		:wikitext('shortname')

	for party_name, party_vals in pairs(data.full) do
		row = root:tag('tr')
		row:wikitext(table_row(party_name, party_vals))
	end
	return tostring(root)

end

return p