Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
store for history
Tag: Reverted
Undid revision 1052916985 by BrandonXLF (talk)
Line 1:
-- Sandbox, do not delete
 
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
function image getImage(frame, image)
local file = nil
if not image then
return nil
end
 
local file = ''
local file = nil
if string.match(image,"(.-)%.(.*)") then
 
file = frame:expandTemplate{title = "flagicon image", args = { image } }
elseifif string.match(image, "(.-)%s%.(.-%*)") then
file = frame:expandTemplate{title = "flagicon image", args = { image } }
ifelseif string.match(image, "(.-)%.s%(.*-%)") then
local country, var = string.match(image,"(.-)%s%((.-)%)")
file = frame:expandTemplate{title = "flagdeco", args = { country, var } }
else
file = frame:expandTemplate{title = "flagdeco", args = { image } }
end
 
return file
end
 
function p.main getCountry(framecountry)
local title = mw.title.new(country)
if not title or not title.exists then
return htmlcountry
end
return '[[' .. country .. ']]'
end
 
function p.main(frame)
local args = getArgs(frame)
local outhasImages = ''false
local imagesentries = {}
local countries = {}
local i = 1
 
while args['c' .. i] do
images[i] = image(frame, while args['i' ..+ i2]) do
image = getImage(frame, args[i])
countries[i] = args['c' .. i] .. (args['y' .. i] and ' (' .. args['y' .. i] .. ')' or '')
i = i + 1
table.insert(entries, {
image = image,
country = getCountry(args[i + 1]),
countries[i] post = args['c' .. i] ..+ (args['y' .. i2] and ' (' .. args['y'i ..+ i2] .. ')' or '')
})
if image then
hasImages = true
end
i = i + 13
end
local hasimages = next(images)
if args[i] then
for i, country in ipairs(countries) do
return require('Module:Error').error{'Uneven number of parameters, there should be 3 parameters per entry.'}
out = out .. '<tr>'
out = out .. (images[i] and ('<td style="vertical-align:top;">' .. images[i] .. '</td>') or (hasimages and '<td></td>' or ''))
out = out .. '<td style="width:100%;vertical-align:top;">' .. country .. '</td>'
out = out .. '</tr>'
end
local html = '<table style="padding:5px;float:' .. (args.float or 'left') .. ';background-color:#f8f9fa;border:1px solid #aaa;width:20em;font-size:90%;">'
local outTable = mw.html.create('table')
html = html .. '<tr><th colspan="' .. (hasimages and 2 or 1) .. '" style="text-align:center;font-size:larger;font-weight:bold;">' .. (args.title and args.title or 'Historical affiliations') .. '</th></tr>'
:css({
html = html .. out
padding = '5px',
html = html .. '</table>'
float = args.float or 'left',
return html
['background-color'] = '#f8f9fa',
border = '1px solid #aaa',
width = '20em',
['font-size'] = '90%'
})
 
outTable:tag('tr')
:tag('th')
:attr('colspan', hasImages and 2 or 1)
:css({
['text-align'] = 'center',
['font-size'] = 'larger',
['font-weight'] = 'bold'
})
:wikitext(args.title and args.title or 'Historical affiliations')
 
for i, countryentry in ipairs(countriesentries) do
local row = outTable:tag('tr')
if entry.image then
row:tag('td')
:css('vertical-align', 'top')
:wikitext(entry.image)
elseif hasImages then
row:tag('td')
end
row:tag('td')
:css({
width = '100%',
['vertical-align'] = 'top'
})
:wikitext(entry.country .. entry.post)
end
 
return tostring(outTable)
end