Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 21:
local file = nil
 
if string.match(image, "'.-%."') then
file = mw.getCurrentFrame():expandTemplate{title = "'flagicon image"', args = {image}}
elseif string.match(image, "'.-%s %(.-%)"') then
local country, var = string.match(image,"'(.-)%s %((.-)%)"')
file = mw.getCurrentFrame():expandTemplate{title = "'flagdeco"', args = {country, var, noredlink = 'y'}}
else
file = mw.getCurrentFrame():expandTemplate{title = "'flagdeco"', args = {image, noredlink = 'y'}}
end
 
Line 35:
function p.main(frame)
local args = getArgs(frame)
local hasImageshasFlags = false
local entries = {}
local i = 1
local keyHandles = {
[''] = getCountry,
timespan['date'] = getTimespan(val),
imageflag = getImage(val)
}
 
for i, entry in ipairs(args) do
local country,
local timespan, image
local flag
local data = {}
for line in args[i]entry:gmatch('[^\n]+') do
line = mw.text.trim(line)
local key, val = line:match('^([a-z]*):? *(.*)$')
if keyHandles[key == ''] then
countrydata[key] = getCountrykeyHandles[key](val)
elseif key == 'date' then
timespan = getTimespan(val)
elseif key == 'flag' then
image = getImage(val)
else
return require('Module:Error').error{'Invalid key ' .. key .. ' in argument ' .. i}
Line 58 ⟶ 62:
end
if not countrydata[''] then
return require('Module:Error').error{'A country is required in argument ' .. i}
end
if not timespandata['date'] then
return require('Module:Error').error{'A date is required in argument ' .. i}
end
table.insert(entries, {
country = country,
timespan = timespan,
image = image,
})
if imagedata.flag then
hasImageshasFlags = true
end
table.insert(entries, {data)
i = i + 1
Line 91:
outTable:tag('tr')
:tag('th')
:attr('colspan', hasImageshasFlags and 2 or 1)
:css({
['text-align'] = 'center',
Line 102:
local row = outTable:tag('tr')
if entry.imageflag then
row:tag('td')
:css('vertical-align', 'top')
:wikitext(entry.imageflag)
elseif hasImageshasFlags then
row:tag('td')
end
Line 115:
['vertical-align'] = 'top'
})
:wikitext(entry.country[''] .. entry.timespan['date'])
end