Module:Political party/testtable
Appearance
![]() | This module depends on the following other modules: |
local p = {}
local all_parties = {}
local function getFirstLetter(party)
index = mw.ustring.sub(party, 1, 1)
-- Set index for non-A-Z starts
if string.match(index, '%A') then
index = '1'
end
return index
end
local function get_values(party)
party = stripwhitespace(party or '')
local colors = nil
colors = all_parties[party]
if ( colors and type(colors) == 'string' ) then
colors = all_parties[colors]
end
return colors or unknown
end
-- 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 party = stripToNil(args[1]) or error('parameter 1 should be a party name')
--local out_type = stripToNil(args[2]) or error('parameter 2 should be the output type')
local index = args['letter']
-- Load data from submodule
local data = mw.loadData('Module:Political names/' .. index)
local all_parties = data.full
-- helper function
local function table_row(t, c)
local res = mw.html.create('')
if( c[1] ) then
res:tag('td'):wikitext(t)
else
res:tag('td'):wikitext(t .. ' <span class=error>ERROR</span>')
end
res:tag('td')
:css('background', 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', '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')
:addClass('unsortable')
:wikitext('abbrev')
row:tag('th')
:addClass('unsortable')
:wikitext('shortname')
for k, party in pairs( all_parties ) do
row = root:tag('tr')
row:wikitext(table_row(party, get_values(party)))
end
return tostring(root)
end
return p