Module:Infobox rune
Appearance
Implements {{Infobox rune}}
--
-- This module implements {{Infobox rune}}
--
require('Module:No globals')
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.infobox(frame)
args = getArgs(frame)
local langlinks = {
pg = '[[Proto-Germanic language|Proto-Germanic]]',
oe = '[[Old English]]',
on = '[[Old Norse]]'
}
local shapelinks = {
pg = '[[Elder Futhark]]',
oe = '[[Anglo-Saxon runes|Futhorc]]',
on = '[[Younger Futhark]]'
}
local let2num = {
a = '1',
b = '2',
c = '3',
d = '4',
e = '5'
}
-- fill in the entries
local entrynames = {'lang', 'name', 'meaning', 'shape', 'unicode',
'unicode hex', 'transliteration', 'transcription', 'IPA', 'position'}
local entries = {}
for k = 1, #entrynames do
entries[entrynames[k]] = nil
end
for k, v in pairs(args) do
k = '' .. k
local pre, num, let = k:match('^(lang)([1-3])()$')
or k:match('^(name)([1-3])([a-e]?)$')
or k:match('^(meaning)([1-3]?)([a-e]?)$')
or k:match('^(shape)([1-3]?)([a-e]?)$')
or k:match('^(unicode)([1-3]?)([a-e]?)#')
or k:match('^(unicode hex)([1-3]?)([a-e]?)$')
or k:match('^(transliteration)([1-3]?)([a-e]?)$')
or k:match('^(transcription)([1-3]?)([a-e]?)$')
or k:match('^(IPA)([1-3]?)([a-e]?)$')
or k:match('^(position)([1-3]?)([a-e]?)$')
if num then
num = tonumber[num]
if let then
if entries[pre] and type(entries[pre]) == 'table' then
if entries[pre][num] and type(entries[pre][num]) == 'table' then
entries[pre][num][tonumber(let2num[let])] = v
else
entries[pre][num] = {nil, nil, nil, nil, nil}
entries[pre][num][tonumber(let2num[let])] = v
end
else
entries[pre] = {nil, nil, nil}
entries[pre][num] = {nil, nil, nil, nil, nil}
entries[pre][num][tonumber(let2num[let])] = v
end
else
if entries[pre] and type(entries[pre]) == 'table' then
entries[pre][num] = v
else
entries[pre] = {nil, nil, nil}
entries[pre][num] = v
end
end
elseif pre then
entries[pre] = v
end
end
local subcols = {0, 0, 0}
-- determine the number of subcolumns per column
for k = 1, #entrynames do
local e = entries[entrynames[k]]
if e then
if type(e) == 'table' then
for j = 1,3 do
if e[j] and type(e[j]) == 'table' then
local n = #(e[j])
if n > subcols[j] then
subcols[j] = n
end
elseif e[j] then
if 1 > subcols[j] then
subcols[j] = 1
end
end
end
end
end
end
local lets = {'a', 'b', 'c', 'd', 'e'}
-- build the table
local root = mw.html.create()
root = root
:tag('table')
:addClass('wikitable')
:addClass('plainrowheaders')
:css('float', args.float or 'right')
:css('clear', (args.float == 'none' and 'both') or args.float or 'right')
:css('width', args.width or 'auto')
:css('margin', args.float == 'left' and '0 1.0em 1.0em 0' or '0 0 1.0em 1.0em')
:css('font-size', '88%')
-- Name
local row = root:tag('tr')
row:tag('th')
:attr('scope', 'row')
:attr('rowspan', 3)
:css('vertical-align', 'middle')
:wikitext('Name')
for k=1,3 do
if subcols[k] > 0 then
local v = langlinks[(args['lang' .. k] or ''):lower()] or args['lang' .. k]
row:tag('th')
:attr('scope', 'col')
:attr('colspan', (subcols[k] > 1) and subcols[k] or nil)
:wikitext(v)
end
end
return tostring(root)
end
return p