9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/mediawiki_tool/calendar.rb', line 9
def self.month(username: 'USERNAME', month: Time.now.month, year: Time.now.year)
calendar_first = Date.new(year,month).beginning_of_week
calendar_last = Date.new(year,month,-1).end_of_week
table_head = Date::ABBR_DAYNAMES.rotate.map(&:upcase).unshift('').map(&:wiki_th).join("\n")
table_lines = (calendar_first..calendar_last).group_by(&:cweek).map do |_, days|
line_head = week_link(username, days.first).wiki_th
line_elements = days.map do |day|
((day.month==month) ? day_link(username, day) : '').wiki_td(align: 'middle')
end
line_elements.unshift(line_head).join("\n")
end
"{|\n" + table_lines.unshift(table_head).join("\n|-\n") + "\n|}"
end
|