Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 4:
local p = {}
 
local function getImagegetCountry(frame, imagecountry)
local title = mw.title.new(country)
if string.match(image, ".-%+") then
image = string.match(image, ".-%+(.+)")
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 = nil
 
if string.match(image, ".-%.") then
file = framemw.getCurrentFrame():expandTemplate{title = "flagicon image", args = {image}}
elseif string.match(image, ".-%s%(.-%)") then
local country, var = string.match(image,"(.-)%s%((.-)%)")
file = framemw.getCurrentFrame():expandTemplate{title = "flagdeco", args = {country, var, noredlink = 'y'}}
else
file = framemw.getCurrentFrame():expandTemplate{title = "flagdeco", args = {image, noredlink = 'y'}}
end
 
return file
end
 
function getCountry(country)
if string.match(country, ".-%+") then
country = string.match(country, "(.-)%+")
end
local title = mw.title.new(country)
if not title or not title.exists then
return country
end
return '[[' .. country .. ']]'
end
 
Line 43 ⟶ 39:
local i = 1
 
whilefor args[i, +entry 1]in ipairs(args) do
local country, timespan, image
image = getImage(frame, args[i])
for line in args[i]:gmatch('[^\n]+') do
line = mw.text.trim(line)
local key, val = line:match('^([a-z]*):? *(.*)$')
if args[i]not key then
country = getCountry(args[i]val),
elseif key == 'date' then
timespan = getTimespan(val)
elseif key == 'flag' then
image = getImage(frame, args[i]val)
else
return require('Module:Error').error{'UnevenInvalid numberkey of' parameters,.. therekey should.. be' 2in parametersargument per' entry.'. i}
end
end
if not country then
return require('Module:Error').error{'A country is required in argument ' .. i}
end
if not timespan then
return require('Module:Error').error{'A date is required in argument ' .. i}
end
table.insert(entries, {
country = string.match(country, "(.-)%+")
timespan = timespan,
image = image,
country = getCountry(args[i]),
post = args[i + 1] and ' (' .. args[i + 1] .. ')' or ''
})
Line 56 ⟶ 76:
end
i = i + 21
end
if args[i] then
return require('Module:Error').error{'Uneven number of parameters, there should be 2 parameters per entry.'}
end
Line 99 ⟶ 115:
['vertical-align'] = 'top'
})
:wikitext(entry.country .. entry.posttimespan)
end