Class: AutomaticUpcomingEvents
- Inherits:
-
Object
- Object
- AutomaticUpcomingEvents
- Defined in:
- lib/helpers/default-helpers.rb
Instance Method Summary collapse
-
#initialize(wiki, calendar, days_passed = 0, days_future = 7, pagename = 'Upcoming Events', author = "AutomaticUpcomingEvents") ⇒ AutomaticUpcomingEvents
constructor
A new instance of AutomaticUpcomingEvents.
- #page_revised(page) ⇒ Object
- #render_event(name) ⇒ Object
- #render_upcoming_events ⇒ Object
Constructor Details
#initialize(wiki, calendar, days_passed = 0, days_future = 7, pagename = 'Upcoming Events', author = "AutomaticUpcomingEvents") ⇒ AutomaticUpcomingEvents
Returns a new instance of AutomaticUpcomingEvents.
327 328 329 330 331 |
# File 'lib/helpers/default-helpers.rb', line 327 def initialize( wiki, calendar, days_passed = 0, days_future = 7, pagename = 'Upcoming Events', = "AutomaticUpcomingEvents" ) @wiki, @calendar, @days_passed, @days__future, @pagename, @author = wiki, calendar, days_passed, days_future, pagename, @wiki.watch_for( :page_revised ) { |event, page| page_revised( page ) } @wiki.watch_for( :day ) { render_upcoming_events } end |
Instance Method Details
#page_revised(page) ⇒ Object
333 334 335 |
# File 'lib/helpers/default-helpers.rb', line 333 def page_revised( page ) render_upcoming_events if page.name =~ /^\d\d\d\d ... \d\d/ end |
#render_event(name) ⇒ Object
349 350 351 352 353 354 355 356 357 |
# File 'lib/helpers/default-helpers.rb', line 349 def render_event( name ) page = @wiki.page( name ) headings = page.textile.select { |line| line =~ /^h\d\./ } headings = headings.map { |heading| heading.to_s[4..-1].strip } headings = [ page.textile.first_lines(1) ] if headings.empty? content = " [[ #{headings.shift} => #{page.name} ]] |\n" headings.each { |heading| content << "| | [[ #{heading} => #{page.name} ]] |\n" } content end |
#render_upcoming_events ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/helpers/default-helpers.rb', line 337 def render_upcoming_events content = "<div class='upcomingevents'>\n\n" Time.now.day.upto( Time.now.day+7 ) do |day| time = @calendar.time_for( Time.now.month, day ) content << "| [[ #{time.relative_day} => #{@calendar.day_pagename( time )} ]] |" content << (@wiki.exists?( @calendar.day_pagename(time) ) ? render_event( @calendar.day_pagename( time ) ) : " |\n") end content << "\n\np(more). [[(more) => #{@calendar.month_pagename}]]\n\n" content << "\n</div>\n" @wiki.revise( "Upcoming Events", content , "AutomaticCalendar" ) end |