Module:Event list: Difference between revisions

Content deleted Content added
creating a lua version of template:event list which was originally created by User:Pee Tern
 
m Pppery moved page Module:EventList to Module:Event list without leaving a redirect: Make module name match template name
 
(8 intermediate revisions by one other user not shown)
Line 8:
local title = args['title'] or 'Chronology of events for ' .. mw.title.getCurrentTitle().text
local columnscols = tonumber(args['columns'] or '2') or 2
local datewidth = args['datewidth'] or '-1'
local datealign = args['datealign'] or ''
local collapse = args['collapse'] or 'collapsed'
 
-- append the suffix to the date width or set to auto
if (tonumber(datewidth) or -1) >= 0 then
datewidth = tonumber(datewidth) .. 'px%'
else
datewidth = 'auto'
Line 24 ⟶ 25:
local i = tonumber(tostring(k):match( '^%s*date([%d]+)%s*$' ) or '-1')
if i ~= -1 then
table.insert(eventnums, ki)
else
i = tonumber(tostring(k):match( '^%s*event([%d]+)%s*$' ) or '-1')
if i ~= -1 then
table.insert(eventnums, ki)
else
i = tonumber(k) or -1
Line 55 ⟶ 56:
:css('width', '100%')
-- Add the title
root:tag('tr'):tag('th'):attr('colspan', columnscols):wikitext(title)
-- Create the row to hold the columns
local outerrow = root:tag('tr'):css('vertical-align', 'top')
local percol = math.ceil((#eventnums) / columnscols)
k = 0
for i = 1,columnscols do
local outercell = outerrow:tag('td'):css('width', (math.floor(10/cols)/10) .. '%')
local innertable = outercell:tag('table')
:css('width', '100%')
:css('border', 'none')
local tr = innertable:tag('tr')
:css('cellspacing', '-1px')
tr:tag('th'):attr('scope', 'col'):css('width', datewidth):wikitext('Date')
:css('cellpadding', '0px')
tr:tag('th'):attr('scope', 'col'):wikitext('Event description')
:css('margin', '-1px')
:css('font-size', '88%')
:css('line-height', '100%')
local tr = innertable:tag('tr'):css('vertical-align', 'top')
tr:tag('th')
:attr('scope', 'col')
:css('width', datewidth)
:css('text-align', (datealign ~= '') and datealign or 'left')
:css('border-bottom', '1px #aaa solid')
:wikitext('Date')
tr:tag('th')
:attr('scope', 'col')
:css('text-align', 'left')
:css('border-bottom', '1px #aaa solid')
tr:tag('th'):attr('scope', 'col') :wikitext('Event description')
for j=1,percol do
k = k + 1
localif nk <= #eventnums[k] then
local n = tonumber(eventnums[k])
local d = (args['date' .. n] or '') .. (args[2*(kn-1)+1] or '')
local e = (args['event' .. n] or '') .. (args[2*(kn-1)+2] or '')
if d ~= '' or e ~= '' then
tr = innertable:tag('tr'):css('vertical-align', 'top')
tr:tag('td'):css('text-align',(datealign ~= '') and datealign or nil):wikitext(d)
tr:tag('td'):wikitext(e)
end
end
end