Module:Current events calendar/sandbox: Difference between revisions

Content deleted Content added
reduce getDateStuff to a single non-temporary struct
tstyles
 
Line 56:
if dateStuff.argsDate or isLinkworthy(day, currentDay) then
table.insert(calStrings, string.format(
"'''[[#%d %s %d|  %d  ]]'''",
currentYear,
currentMonth,
Line 73:
local monthAndYear = dateStuff.monthAndYear
local root = mw.html.create('table')
-- The next two lines help to make the table-layout-based Archive pages look
-- good. When the Archives have been converted to a grid-based layout, this
-- logic can be removed, and the corressponding CSS margin attribute can be
-- simplified.
local temporaryMarginAdjustment = "auto !important"
if dateStuff.argsDate then temporaryMarginAdjustment = "8px 0 0 8px" end
root
:addClass('infoboxcurrent-events-calendar')
-- The next two lines help to makeMake the table-layout-based Archive pages look good. When the Archives
:css{
-- good. When the Archives have been converted to a grid-based layout, this logic can be removed,
display = 'table',
-- logic can be removed, and the corressponding CSS margin attribute can be simplified.
width = '100%',
:addClass(dateStuff.argsDate and 'current-events-calendar-archive')
float = 'initial',
['max-width'] = '350px',
margin = temporaryMarginAdjustment,
['text-align'] = 'center',
['background-color'] = '#f5faff',
border = '1px solid #cedff2'
}
-- Headings
:tag('trcaption')
:csstag('background-color', '#cedff2span')
:tagaddClass('thnoprint')
:wikitext(makeWikilink(
:css{['text-align'] = 'center'}
'Portal:Current events/' .. dateStuff.previousMonthAndYear,
:tag('span')
:addClass('noprint')
))
:wikitext(makeWikilink(
'Portal:Current events/' .. dateStuff.previousMonthAndYear,
'◀'
))
:done()
:done()
:tag('thspan')
:attr('colspan', '5')
:css{['text-align'] = 'center'}
:wikitext(makeWikilink(
'Portal:Current events/' .. monthAndYear,
Line 112 ⟶ 94:
))
:done()
:tag('thspan')
:addClass('noprint')
:css{['text-align'] = 'center'}
:wikitext(makeWikilink(
:tag('span')
'Portal:Current events/' .. dateStuff.nextMonthAndYear,
:addClass('noprint')
''
:wikitext(makeWikilink(
:done())
'Portal:Current events/' .. dateStuff.nextMonthAndYear,
'▶'
))
 
-- Day of week headings
local dayHeadingRow = root:tag('tr')
local weekdays = {'S', 'M', 'T', 'W', 'T', 'F', 'S'}
for i_, weekday in ipairs(weekdays) do
dayHeadingRow:tag('th'):wikitext(weekday)
:css{['width'] = '14%', ['text-align'] = 'center'}
:wikitext(weekday)
end
 
Line 138 ⟶ 116:
cellCount = cellCount + 1
-- Use a blank cell if there is no corresponding dateString
local dayString = dayStrings[cellCount] or " "''
weeklyRow:tag('td'):wikitext(dayString)
:css{['text-align'] = 'center'}
:wikitext(dayString)
end
end
Line 148 ⟶ 124:
if not dateStuff.argsDate then -- No footer necessary on Archive pages.
root:tag('tr')
:addClass('current-events-calendar-footer')
:addClass('noprint')
:tag('td')
:attr('colspan', '7')
:css{
['padding-top'] = '3px',
['padding-bottom'] = '5px',
['font-size'] = '78%',
['text-align'] = 'right'
}
:wikitext(makeWikilink(
'Portal:Current events/' .. monthAndYear,
Line 168 ⟶ 139:
function p.main(frame)
local argsDate = nil
if (frame and frame.args and frame.args.year and frame.args.month) then
-- If a date is passed in, assume that the display page is an Archive page.
-- If no date passed in, assume that the display page is the current Current Events page
Line 175 ⟶ 146:
end
local dateStuff = getDateStuff(argsDate)
return frame:extensionTag{
local dayStrings = makeDayStrings(dateStuff)
name = 'templatestyles',
return export(dayStrings, dateStuff)
args = { src = 'Module:Current events calendar/styles.css' }
local} dayStrings =.. export(makeDayStrings(dateStuff), dateStuff)
end