Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
No edit summary
store for history
Tag: Reverted
Line 1:
-- Sandbox, do not delete
 
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
function getImageimage (frame, image)
local file = nil
if not image then
return nil
end
local file = ''
 
elseifif string.match(image, "(.-)%s%.(.-%*)") then
local file = nil
file = frame:expandTemplate{title = "flagicon image", args = { image } }
 
ifelseif string.match(image, "(.-)%.s%(.*-%)") then
file = frame:expandTemplate{title = "flagicon image", args = {image}}
elseif 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 getCountryp.main (countryframe)
local title = mw.title.new(country)
if not title or not title.exists then
return country
end
return '[[' .. country .. ']]'
end
 
function p.main(frame)
local args = getArgs(frame)
local hasImagesout = false''
local entriesimages = {}
local countries = {}
local i = 1
while args['c' .. i] do
 
while images[i] = image(frame, args['i' +.. 2i] do)
postcountries[i] = args['c' .. i] +.. 2(args['y' .. i] and ' (' .. args[i'y' +.. 2i] .. ')' or '')
image = getImage(frame, args[i])
i = i + 31
table.insert(entries, {
image = image,
country = getCountry(args[i + 1]),
post = args[i + 2] and ' (' .. args[i + 2] .. ')' or ''
})
if image then
hasImages = true
end
i = i + 3
end
local hasimages = next(images)
for i, entrycountry in ipairs(entriescountries) do
if args[i] then
out = out .. '<tr>'
return require('Module:Error').error{'Uneven number of parameters, there should be 3 parameters per entry.'}
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%;">'
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>'
local outTable = mw.html.create('table')
html = html .. out
:css({
html = html .. '</table>'
padding = '5px',
return countryhtml
float = args.float or 'left',
['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, entry in ipairs(entries) 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