-- Sandbox, do not delete
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
local function getCountry(country)
local title = mw.title.new(country)
if not title or not title.exists then
return country
end
return '[[' .. country .. ']]'
end
local function getTimespan(timespan)
return ' (' .. timespan .. ')'
end
local function getImage(image)
local file = null
if string.match(image, '.-%.') then
file = mw.getCurrentFrame():expandTemplate{title = 'flagicon image', args = {image}}
elseif string.match(image, '.- %(.-%)') then
local country, var = string.match(image,'(.-) %((.-)%)')
file = mw.getCurrentFrame():expandTemplate{title = 'flagdeco', args = {country, var, noredlink = 'y'}}
else
file = mw.getCurrentFrame():expandTemplate{title = 'flagdeco', args = {image, noredlink = 'y'}}
end
return file
end
function p.main(frame)
local args = getArgs(frame)
local hasFlags = false
local entries = {}
local i = 1
local knownKeys = {
[''] = true,
['date'] = true,
flag = true
}
for i, entry in ipairs(args) do
local country
local timespan
local flag
local data = {}
for line in entry:gmatch('[^\n]+') do
line = mw.text.trim(line)
local key, val = line:match('^([a-z]*):? *(.*)$')
if knownKeys[key] then
data[key] = val
else
return require('Module:Error').error{'Invalid key ' .. key .. ' in argument ' .. i}
end
end
if data[''] then
data[''] = getCountry(data[''])
else
return require('Module:Error').error{'A country is required in argument ' .. i}
end
if data['date'] then
data['date'] = getTimespan(data['date'])
else
return require('Module:Error').error{'A date is required in argument ' .. i}
end
if data.flag then
hasFlags = true
end
local noFlag = yesno(data['flag']) == false
data['flag'] = getImage(
noFlag
and ''
or (data['flag'] == '' or data['flag'] == nil)
and data['']
or data['flag'])
table.insert(entries, data)
end
local container = mw.html.create('div')
:addClass('historical-affiliation')
:css('float', args.float or 'left')
local titleId = math.random()
container:tag('div')
:attr('id', titleId)
:addClass('historical-affiliation-title')
:wikitext(args.title and args.title or 'Historical affiliations')
local list = container:tag('ul')
:attr('aria-labelledby', titleId)
:addClass('historical-affiliation-list')
for i, entry in ipairs(entries) do
local item = list:tag('li');
item:tag('span')
:wikitext(entry.flag)
item:tag('span')
:wikitext(entry[''] .. entry['date'])
end
return tostring(container) .. frame:extensionTag{
name = 'templatestyles',
args = { src = 'User:BrandonXLF/J/styles.css' }
}
end
return p