https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ACountry_population%2Fsandbox
Module:Country population/sandbox - Revision history
2025-06-01T18:13:52Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:Country_population/sandbox&diff=1117367412&oldid=prev
WOSlinker: use require('strict') instead of require('Module:No globals')
2022-10-21T10:01:22Z
<p>use require('strict') instead of require('Module:No globals')</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 10:01, 21 October 2022</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>require('<del style="font-weight: bold; text-decoration: none;">Module:No globals</del>')</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>require('<ins style="font-weight: bold; text-decoration: none;">strict</ins>')</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local fn = require('Module:Formatnum')</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local fn = require('Module:Formatnum')</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local mm = require('Module:Math')</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local mm = require('Module:Math')</div></td>
</tr>
</table>
WOSlinker
https://en.wikipedia.org/w/index.php?title=Module:Country_population/sandbox&diff=1022343975&oldid=prev
Guarapiranga: A couple of improvements
2021-05-10T00:13:28Z
<p>A couple of improvements</p>
<p><b>New page</b></p><div>require('Module:No globals')<br />
local fn = require('Module:Formatnum')<br />
local mm = require('Module:Math')<br />
local p ={}<br />
local pargs ={}<br />
local args={}<br />
local data={}<br />
<br />
<br />
p.main = function(frame) -- called from template<br />
pargs = frame:getParent().args<br />
local output <br />
<br />
if output then<br />
return frame:preprocess(output)<br />
end<br />
<br />
return p.errormsg("No valid options")<br />
end<br />
function p.getPattern(section)<br />
local pattern = '<section begin=' .. section ..'[ ]*/>(.-)<section end='..section..'[ ]*/>'<br />
return pattern<br />
end<br />
function p.getPopulationData(frame)<br />
<br />
local page = "List of countries by population (United Nations)"<br />
data['dates'] = {}<br />
data['total'] = {}<br />
data.total['latest'] = 0<br />
data.total['previous'] = 0<br />
data.total['projected'] = 0<br />
<br />
--local total = 0<br />
--local totalProjected = 0<br />
local count = 0<br />
local title = mw.title.new( page) -- , ns) -- creates object if page doesn't exist (and valid page name)<br />
--TODO: could use mw.title.makeTitle(), but that needs ns<br />
<br />
local content = title:getContent()<br />
<br />
-- get dates <br />
for value in string.gmatch( content , p.getPattern("date_1") ) do<br />
data.dates['latest']=value -- date of latest data <br />
end<br />
for value in string.gmatch( content , p.getPattern("date") ) do<br />
data.dates['previous']=mw.getContentLanguage():formatDate('j F Y', value)<br />
end <br />
data.dates['today'] = mw.getContentLanguage():formatDate('j F Y') -- today's date (for formatting see https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time)<br />
<br />
-- get population data for each country passes as parameter<br />
for k,v in pairs(args) do<br />
local country = mw.text.trim(v)<br />
<br />
-- get population data from section <br />
local section = country .. "_1"<br />
for value in string.gmatch( content , p.getPattern(section) ) do<br />
<br />
count=count+1<br />
data[count] = {}<br />
data[count]['country'] = country<br />
data[count]['populationString'] = frame:preprocess(value)<br />
local raw = string.gsub(data[count]['populationString'], ",", "") -- strip formatting from number string<br />
data[count]['populationNumber'] = tonumber(raw)<br />
data.total['latest'] = data.total['latest'] + data[count]['populationNumber']<br />
<br />
local section = country .. "_0"<br />
for value2 in string.gmatch( content , p.getPattern(section) ) do<br />
data[count]['populationString2'] = frame:preprocess(value2)<br />
local raw = string.gsub(data[count]['populationString2'], ",", "") -- strip formatting from number string<br />
data[count]['populationNumber2'] = tonumber(raw)<br />
data.total['previous'] = data.total['previous'] + data[count]['populationNumber2']<br />
<br />
data[count]['populationIncrement']=data[count]['populationNumber'] - data[count]['populationNumber2']<br />
data[count]['populationGrowth'] =data[count]['populationIncrement']/data[count]['populationNumber2']<br />
data[count]['populationDouble'] = p.getPopulationDoubleTime(data[count]['populationNumber'],data[count]['populationNumber2'])<br />
<br />
data[count]['populationProjected'] = p.getPopulationProjection(data[count]['populationNumber'],data[count]['populationNumber2'])<br />
data.total['projected'] = data.total['projected'] + data[count]['populationProjected'] <br />
end<br />
<br />
end<br />
end<br />
<br />
return true<br />
end<br />
<br />
-- estimate time to double population based on latest growth rate<br />
function p.getPopulationDoubleTime(latest,previous)<br />
local growth = (latest - previous) / previous<br />
local doubleTime = math.log( 2 ) / math.log(1 + growth)<br />
return doubleTime<br />
end<br />
<br />
-- estimate today's population based on latest growth rate<br />
function p.getPopulationProjection(latest,previous)<br />
local ay = ( mw.getCurrentFrame():callParserFunction{ name = '#time', args = { "U", data.dates['today'] } }<br />
- mw.getCurrentFrame():callParserFunction{ name = '#time', args = { "U", data.dates['previous'] } })<br />
/60/60/24/365.2425 -- number of years since first date until today<br />
local projected = math.pow(previous, 1 - ay ) * math.pow(latest, ay)<br />
return projected<br />
end<br />
<br />
--[[ sort rows by population (defaults to latest population)<br />
TODO add options for sorting columns<br />
]]<br />
function p.sortPopulationData(ByColumn)<br />
<br />
local sort_function = function( a,b )<br />
if (tonumber(a.populationNumber) > tonumber(b.populationNumber)) then -- primary sort on 'population' -> a before b<br />
return true<br />
end<br />
end<br />
<br />
table.sort(data, sort_function)<br />
end<br />
--[[ Function to get flag icon and handle special cases <br />
1. There is an issue of non-standard sizes when used with static rank column <br />
The three countries with extra height (and the required size parameter) are <br />
Nepal/NPL (size=12px), Switzerland/CHE (size=15px), Vatican/VAT (size=15px)<br />
a few have lower default heights so it doesn't matter (Poland, New Caledonia)<br />
2. Alias, e.g. NEP->NPL, TRI->TTO<br />
]]<br />
function p.getFlagLabel(countryCode)<br />
local output <br />
local templateArgs = { countryCode }<br />
<br />
local size<br />
if countryCode == "CHE" or countryCode == "VAT" then<br />
size="15px"<br />
elseif countryCode == "NPL" then<br />
size="12px"<br />
end<br />
if size then templateArgs['size'] = size end<br />
<br />
-- simple version<br />
--output = mw.getCurrentFrame():expandTemplate{ title = "flaglist", args = templateArgs } <br />
<br />
-- method with fixed-height div and overflow<br />
output = '<div style="height:15px;overflow:visible;" >'<br />
.. mw.getCurrentFrame():expandTemplate{ title = "flaglist", args = templateArgs }<br />
.. '</div>'<br />
<br />
<br />
return output <br />
end<br />
<br />
--[[ output table of data as Wikitext table<br />
]]<br />
function p.tabulateDataWikitext(frame)<br />
<br />
local output<br />
local i = 1<br />
-- output table<br />
output = '{| class="wikitable sortable mw-datatable" style="text-align:right;" ' -- table<br />
output = '|-class=wrap'<br />
output = output --headers (top row)<br />
.. '\n!rowspan=2|#'<br />
.. '\n!rowspan=2|Country'<br />
.. '\n!rowspan=2|Projected population<br/>(' .. data['dates']['today'] .. ')' <br />
.. '\n!rowspan=2|Pct of<br>total'<br />
.. '\n!colspan=2|UN Population estimates'<br />
.. '\n!colspan=2|Annual growth'<br />
.. '\n!rowspan=2|Doubling time<br/>(years)'<br />
<br />
.. '\n|-' -- headers (second row)<br />
.. '\n!' .. data.dates['latest'] <br />
.. '\n!' .. data.dates['previous'] <br />
.. '\n!Increment'<br />
.. '\n!Rate' <br />
<br />
while (data[i]) do -- add rows<br />
output = output .. '\n|-\n|' .. i <br />
output = output .. '\n|style="text-align:left;" |' .. frame:expandTemplate{ title = "flaglist", args = {data[i]['country'] } }<br />
output = output .. '\n| ' .. mm._precision_format(data[i]['populationProjected'],0) <br />
output = output .. '\n| ' .. mm._precision_format(data[i]['populationProjected']/data.total['projected']*100,2) .. "%" -- projected<br />
output = output .. '\n| ' .. data[i]['populationString'] <br />
output = output .. '\n| ' .. data[i]['populationString2'] <br />
output = output .. '\n| ' .. mm._precision_format(data[i]['populationIncrement'],0) <br />
output = output .. '\n| ' .. mm._round(data[i]['populationGrowth']*100,2) .. "%"<br />
output = output .. '\n| ' .. mm._round(data[i]['populationDouble'],0)<br />
i=i+1<br />
end<br />
<br />
local newcell = '\n! style="text-align:right;" | ' <br />
output = output .. '\n|-' -- totals row<br />
.. '\n! !! Total' <br />
.. newcell .. fn.formatNum(mm._round(data.total['projected'],0),"en",0) <br />
.. newcell .. '100%'<br />
.. newcell .. fn.formatNum(data.total['latest'],"en",0) <br />
.. newcell .. fn.formatNum(data.total['previous'],"en",0) <br />
.. newcell .. fn.formatNum(data.total['latest']-data.total['previous'],"en",0)<br />
.. newcell .. fn.formatNum((data.total['latest']-data.total['previous'])/data.total['previous']*100,"en",2).."%"<br />
.. newcell .. mm._precision_format(p.getPopulationDoubleTime(data.total['latest'],data.total['previous']),0)<br />
<br />
output = output .. '\n|}'<br />
return output<br />
end<br />
<br />
<br />
--[[ output table of data as use Lua HTML Library<br />
]]<br />
function p.tabulateData(frame)<br />
<br />
local hideYearsCols = frame.args['hide_years'] or false<br />
local doublingFootnote = frame.args['doubling_note'] or ""<br />
local growthFootnote = frame.args['growth_note'] or ""<br />
<br />
local i = 1<br />
local static = mw.html.create('table'):addClass('wikitable')<br />
<br />
static:tag('tr'):tag('th'):attr('rowspan', 1):wikitext('<br/>'):cssText('border-bottom-color:#eaecf0;')<br />
static:tag('tr'):tag('th'):wikitext('<br/>'):cssText('border-top-color:#eaecf0;')<br />
while (data[i]) do -- add rows<br />
static:tag('tr'):tag('td'):wikitext(i)<br />
i=i+1<br />
end<br />
static:tag('tr'):tag('th'):wikitext('<br/>')<br />
local numRows=i-1<br />
<br />
local tbl = mw.html.create('table'):addClass('wikitable') -- start table<br />
:addClass('sortable')<br />
:addClass('mw-datatable')<br />
:addClass('static-row-numbers') -- prefix with row numbers using css and templatestyles<br />
:addClass('nowrap')<br />
:css('text-align','right')<br />
<br />
local row = tbl:tag('tr') -- header row<br />
:addClass('static-row-header') -- for templatestyles in some skins<br />
--:tag('th'):attr('rowspan', 2):wikitext('#')<br />
row :tag('th'):attr('rowspan', 2):wikitext('Country')<br />
:tag('th'):attr('rowspan', 2):wikitext('Projected population<br/>(' .. data['dates']['today'] .. ')' )<br />
:tag('th'):attr('rowspan', 2):wikitext('Pct of<br>total')<br />
if not hideYearsCols then<br />
row :tag('th'):attr('colspan', 2):wikitext('UN Population estimates')<br />
end<br />
row :tag('th'):attr('colspan', 2):wikitext('Annual growth'..growthFootnote)<br />
:tag('th'):attr('rowspan', 2):wikitext('Doubling time<br/>(years)'..doublingFootnote)<br />
<br />
row = tbl:tag('tr') -- headers (second row)<br />
:addClass('static-row-header') -- for templatestyles in some skins<br />
if not hideYearsCols then<br />
row :tag('th'):wikitext(data.dates['latest'] )<br />
:tag('th'):wikitext(data.dates['previous'] )<br />
end<br />
row :tag('th'):wikitext('Increment')<br />
:tag('th'):wikitext('Rate') <br />
<br />
<br />
i = 1<br />
while (data[i]) do -- add country rows<br />
<br />
local row=tbl:tag('tr') <br />
--row :tag('td'):wikitext(i) <br />
row :tag('td'):cssText("text-align:left;")<br />
:wikitext( p.getFlagLabel(data[i]['country']) )<br />
:tag('td'):wikitext( mm._precision_format(data[i]['populationProjected'],0) )<br />
:tag('td'):wikitext( mm._precision_format(data[i]['populationProjected']/data.total['projected']*100,2) .. "%" ) -- % of projected <br />
if not hideYearsCols then<br />
row :tag('td'):wikitext( data[i]['populationString'] )<br />
:tag('td'):wikitext( data[i]['populationString2'] )<br />
end<br />
row :tag('td'):wikitext( mm._precision_format(data[i]['populationIncrement'],0) )<br />
:tag('td'):wikitext( mm._precision_format(data[i]['populationGrowth']*100,2) .. "%" )<br />
:tag('td'):wikitext( mm._precision_format(data[i]['populationDouble'],0) )<br />
i=i+1<br />
end<br />
<br />
local style = { ['text-align']='right' } <br />
row = tbl:tag('tr') -- totals row<br />
:addClass('static-row-header') -- for templatestyles in some skins<br />
--:tag('th') :wikitext()<br />
row :tag('th') :wikitext('Total')<br />
:tag('th'):css(style):wikitext( fn.formatNum(mm._round(data.total['projected'],0),"en",0) ) <br />
:tag('th'):css(style):wikitext( '100%' )<br />
if not hideYearsCols then<br />
row :tag('th'):css(style):wikitext( fn.formatNum(data.total['latest'], "en",0) )<br />
:tag('th'):css(style):wikitext( fn.formatNum(data.total['previous'],"en",0) )<br />
end<br />
row :tag('th'):css(style):wikitext( fn.formatNum(data.total['latest'] - data.total['previous'],"en",0) )<br />
:tag('th'):css(style):wikitext( fn.formatNum((data.total['latest'] - data.total['previous']) / data.total['previous'] * 100,"en",2).."%" )<br />
:tag('th'):css(style):wikitext( mm._precision_format(p.getPopulationDoubleTime(data.total['latest'],data.total['previous']),0) )<br />
<br />
-- return tostring(tbl) -- return table without row numbers<br />
<br />
-- use separate column for static row numbers<br />
-- return '{|\n|style="vertical-align:top;" |' .. tostring(static) .. '\n|' .. tostring(tbl) .. '\n|}'<br />
<br />
-- use css method and templatestyles to prefix row numbers<br />
return p.templateStyle( frame, "Template:Static_row_numbers/styles.css" ) .. tostring(tbl)<br />
end<br />
<br />
<br />
--[[ currently the main entry function<br />
takes list of country codes<br />
gets population data from "List of countries by population (United Nations)"<br />
outputs sorted table<br />
]]<br />
function p.populations(frame)<br />
<br />
args = frame.args --TODO handle parent args for template<br />
<br />
local page = "List of countries by population (United Nations)"<br />
<br />
local title = mw.title.new( page) -- , ns) -- creates object if page doesn't exist (and valid page name)<br />
--TODO: could use mw.title.makeTitle(), but that needs ns<br />
local output = ""<br />
if title and title.exists then <br />
local content = title:getContent()<br />
<br />
if not p.getPopulationData(frame) then<br />
return p.errormsg("Error retrieving data.")<br />
end<br />
<br />
p.sortPopulationData("latest")<br />
<br />
--output = p.tabulateDataWikitext(frame) -- version building table with Wikitext<br />
output = p.tabulateData(frame) -- version building table with mw.html library<br />
<br />
else<br />
return '<span class="error">No page title found</span>'<br />
end<br />
<br />
local test = "test: " <br />
local number=5435.12345 <br />
test= fn.formatNum(5435.12345,"en",0)<br />
--test= frame:expandTemplate{ title = "formatnum", args = { totalProjected ,"en",0 } }<br />
--test=frame:callParserFunction{ name = 'formatnum', args = { totalProjected, decs=2 } } <br />
<br />
<br />
return output --.. test<br />
end<br />
-- function for pie chart<br />
function p.piechart(frame)<br />
<br />
args = frame.args --TODO handle parent args for template<br />
<br />
local page = "List of countries by population (United Nations)"<br />
<br />
local title = mw.title.new( page) -- , ns) -- creates object if page doesn't exist (and valid page name)<br />
--TODO: could use mw.title.makeTitle(), but that needs ns<br />
local output = ""<br />
if title and title.exists then <br />
local content = title:getContent()<br />
<br />
if not p.getPopulationData(frame) then<br />
return p.errormsg("Error retrieving data.")<br />
end<br />
<br />
p.sortPopulationData("latest")<br />
<br />
--output = p.tabulateDataWikitext(frame) -- version building table with Wikitext<br />
output = p.makePieChart(frame) -- version building table with mw.html library<br />
<br />
else<br />
return '<span class="error">No page title found</span>'<br />
end<br />
<br />
<br />
<br />
return output --.. test<br />
end<br />
<br />
function p.makePieChart(frame) <br />
<br />
--local args=frame.args<br />
local templateArgs = {}<br />
<br />
templateArgs['caption'] = args['caption'] or "" --'South American population by country' --.. ' (top 8)'<br />
templateArgs['thumb'] = args['thumb'] or "right"<br />
templateArgs['other'] = args['other'] or nil<br />
local maxSlices = tonumber(args['slices']) -- nil if not a number<br />
if type(maxSlices) ~= "number" or maxSlices > 30 or maxSlices < 1 then<br />
maxSlices = 30 -- limit of template -- get number from data<br />
end<br />
<br />
<br />
<br />
<br />
local i=1<br />
while data[i] and i <= maxSlices do<br />
--templateArgs['label'..i] = data[i]['country'] <br />
templateArgs['label'..i] = mw.getCurrentFrame():expandTemplate{ title = "getalias", args = { data[i]['country'], raw='y' } }<br />
templateArgs['value'..i] = mm._round( data[i]['populationNumber']/data.total['latest']*100,1)<br />
templateArgs['color'..i] = args['color'..i] or nil<br />
i=i+1<br />
end<br />
<br />
<br />
--[[{{Pie chart<br />
|caption= South American population by country (top 8)<br />
|other = yes<br />
|label1 = {{getalias|BRA}}<br />
|value1 = {{#expr: {{country population|BRA|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label2 = {{getalias|COL}}<br />
|value2 = {{#expr: {{country population|COL|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label3 = {{getalias|ARG}}<br />
|value3 = {{#expr: {{country population|ARG|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label4 = {{getalias|PER}}<br />
|value4 = {{#expr: {{country population|PER|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label5 = {{getalias|VEN}}<br />
|value5 = {{#expr: {{country population|VEN|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label6 = {{getalias|CHL}}<br />
|value6 = {{#expr: {{country population|CHL|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label7 = {{getalias|ECU}}<br />
|value7 = {{#expr: {{country population|ECU|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
|label8 = {{getalias|BOL}}<br />
|value8 = {{#expr: {{country population|BOL|raw=y}} / {{xyz|Total}} * 100 round 1}}<br />
}} ]] <br />
<br />
local chart = mw.getCurrentFrame():expandTemplate{ title = "Pie chart", args = templateArgs }<br />
<br />
return chart<br />
<br />
<br />
end<br />
<br />
<br />
function p.firstToUpper(str)<br />
return (str:gsub("^%l", string.upper))<br />
end<br />
p.errormsg = function (message)<br />
return '<span class="error">' .. message .. '</span>' <br />
end <br />
<br />
-- Test why was the sort being applied to the wrong level? Fixed <br />
function p.test(frame) -- meant test()<br />
<br />
local tbl = mw.html.create('table'):addClass('wikitable'):addClass('sortable'):addClass('mw-datatable')<br />
:css('text-align','right')<br />
<br />
tbl:tag('tr') -- header row<br />
:tag('th'):attr('rowspan', 2):wikitext('#')<br />
:tag('th'):attr('rowspan', 2):wikitext('A')<br />
:tag('th'):attr('rowspan', 2):wikitext('B')<br />
:tag('th'):attr('colspan', 2):wikitext('C+D'):addClass('unsortable')<br />
:tag('th'):attr('colspan', 2):wikitext('E+F'):addClass('unsortable')<br />
:tag('th'):attr('rowspan', 2):wikitext('G')<br />
<br />
tbl:tag('tr') -- headers (second row)<br />
:tag('th'):wikitext('C'):addClass('sortable')<br />
:tag('th'):wikitext('D'):addClass('sortable')<br />
:tag('th'):wikitext('E'):addClass('sortable')<br />
:tag('th'):wikitext('F') :addClass('sortable') <br />
<br />
<br />
local i = 1<br />
while (i<5) do -- add rows<br />
tbl:tag('tr') <br />
:tag('td'):wikitext(i) <br />
:tag('td'):wikitext("A"..i)<br />
:tag('td'):wikitext("B"..i)<br />
:tag('td'):wikitext(tostring(math.fmod(5-i,2)) .. 'C' .. i )<br />
:tag('td'):wikitext("D"..i)<br />
:tag('td'):wikitext("E"..i)<br />
:tag('td'):wikitext(tostring(math.fmod(5-i,2)) .. 'F' .. i )<br />
:tag('td'):wikitext("G"..i)<br />
i=i+1<br />
end<br />
<br />
local output = '{| class="wikitable sortable mw-datatable" style="text-align:right;" ' -- table<br />
output = output<br />
.. '\n!rowspan=2|#'<br />
.. '\n!rowspan=2|A'<br />
.. '\n!rowspan=2|B' <br />
.. '\n!colspan=2|C+D'<br />
.. '\n!colspan=2|E+F'<br />
.. '\n!rowspan=2|G'<br />
<br />
.. '\n|-' -- headers (second row)<br />
.. '\n!C' <br />
.. '\n!D' <br />
.. '\n!E'<br />
.. '\n!F' <br />
i=1<br />
while (i<5) do -- add rows<br />
output = output .. '\n|-\n|' .. i <br />
output = output .. '\n|A' .. i <br />
output = output .. '\n|B' .. i<br />
output = output .. '\n|' .. tostring(math.fmod(5-i,2)) .. 'C' .. i <br />
output = output .. '\n|D' .. i <br />
output = output .. '\n|E' .. i <br />
output = output .. '\n|' .. tostring(math.fmod(5-i,2)) .. 'F' .. i <br />
output = output .. '\n|G' .. i<br />
i=i+1<br />
end<br />
output = output .. '\n|}'<br />
<br />
return output .. tostring(tbl)<br />
end<br />
<br />
-- function for static rank column<br />
<br />
function p.rank(frame)<br />
<br />
--args = frame.args -- for module TODO allow invoke to work<br />
args = frame:getParent().args -- parent arguments for template<br />
args = frame.args -- invoke arguments for template<br />
<br />
local caption = args['caption'] <br />
local valign = args['valign'] or "top"<br />
local rowHeader = args['row-header'] <br />
local headerPadding = args['header-padding'] or "0px"<br />
local textAlign = args['text-align'] or "right"<br />
local style = args['style'] or ""<br />
local headerHeight = args['header-height'] or ""<br />
local headerLines = args['header-lines'] or 1<br />
local headerText = args['header-text'] or ""<br />
local rows = tonumber(args['rows']) or 0<br />
local rowHeader = args['row-header'] <br />
local rowHeight = args['row-height'] <br />
<br />
local marginRight = "0px"<br />
if rowHeader then marginRight = "-8px" end<br />
local headerValign = "bottom"<br />
if rowHeader then headerValign = "center" end -- copied from template; should be middle?<br />
local linebreaks = ""<br />
if headerLines then<br />
local i=0<br />
while i<tonumber(headerLines) do<br />
linebreaks = linebreaks .. "<br />"<br />
i=i+1<br />
end<br />
end<br />
<br />
--[[<br />
{| <br />
|+'''{{{caption| }}}'''<br />
| valign={{{valign|top}}} |<br />
{| class="wikitable" style="margin-right:{{#if:{{{row-header|}}}|-8px|0px}}; padding:{{{header-padding|0px}}}; text-align:{{{text-align|right}}};{{{style|}}}"<br />
! style=height:{{{header-height|}}} valign={{{header-valign|{{#if: {{{row-header|}}} | center | bottom}}}}} | {{#if:{{{header-lines|}}}|{{repeat|{{#expr:{{{header-lines}}}-1}}|<br>}}}}{{{header-text|}}}<br />
]]<br />
local heightClass = "static-rank-col"<br />
if rowHeight and rowHeight == "large" then<br />
heightClass = "static-rank-col-large"<br />
end<br />
<br />
<br />
local output = '\n{| class="'..heightClass..'"' --start static rank table<br />
if caption then<br />
output = output .. "\n|+'''" .. caption .. "'''"<br />
end<br />
output = output .. '\n|valign=' .. valign .. ' |'<br />
.. '\n{| class="wikitable" style="margin-right:'..marginRight<br />
..'; padding:'..headerPadding<br />
..'; text-align:'..textAlign <br />
..';'.. style<br />
.. '\n! style="height:'..headerHeight..';" valign="'..headerValign ..';" | ' <br />
.. linebreaks .. headerText<br />
<br />
--[[ {{#ifexpr:{{{rows}}}=0|<br /><br />
{{end}}}}{{#ifexpr:{{{rows}}}>=1|{{Static column row |row-height={{{row-height|}}} |number=1 |row-header={{{row-header| }}} }}}}{{#ifexpr:{{{rows}}}=1|<br /><br />
{{end}}}}{{#ifexpr:{{{rows}}}>=2|{{Static column row |row-height={{{row-height|}}} |number=2 |row-header={{{row-header| }}} }}}}{{#ifexpr:{{{rows}}}=2|<br /><br />
{{end}}}<br />
]]<br />
<br />
local i=0<br />
while i<rows do<br />
i=i+1<br />
--output = output .. '\n|-\n|' .. tostring(i) -- simple unformatted version<br />
<br />
--[[ <br /><br />
|- {{#if: {{{row-height|}}}|style="height:{{{row-height|}}}"|}}<br />
{{#if: {{{row-header|}}} | ! | {{!}} }} {{{number}}}<br />
]] <br />
-- version emulating Template:Static column row <br />
local rowStyle = ""<br />
if rowHeight then rowStyle = 'style="height:'..rowHeight..';" |' end<br />
local cellType = "|"<br />
if rowHeader then cellType = "!" end<br />
output = output .. '\n|-' .. rowStyle <br />
.. '\n' .. cellType .. tostring(i) .. '<br />'<br />
end<br />
<br />
output = output .. '\n|}' -- close the static rank table<br />
<br />
<br />
output = output .. '\n|' -- new cell for the main table<br />
<br />
--output = output .. '\n|}' -- unnecessary: the table will be closed with an {{end}} template<br />
<br />
return p.templateStyle( frame, "Static column begin/styles.css" ) .. output<br />
<br />
end<br />
function p.templateStyle( frame, src )<br />
return frame:extensionTag( 'templatestyles', '', { src = src } );<br />
end<br />
return p</div>
Guarapiranga