Class: AutomaticCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/default-helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wiki, month_pagename = '%Y %b', day_pagename = '%Y %b %d', author = "AutomaticCalendar") ⇒ AutomaticCalendar

Returns a new instance of AutomaticCalendar.



273
274
275
276
277
# File 'lib/helpers/default-helpers.rb', line 273

def initialize( wiki, month_pagename = '%Y %b', day_pagename = '%Y %b %d', author = "AutomaticCalendar" )
  @wiki, @month_pagename, @day_pagename, @author = wiki, month_pagename, day_pagename, author
  render_coming_year
  @wiki.watch_for(:month) { render_coming_year }
end

Instance Attribute Details

#day_pagename(date = Time.now) ⇒ Object (readonly)

Returns the value of attribute day_pagename.



271
272
273
# File 'lib/helpers/default-helpers.rb', line 271

def day_pagename
  @day_pagename
end

#month_pagename(month = Time.now.month) ⇒ Object (readonly)

Returns the value of attribute month_pagename.



271
272
273
# File 'lib/helpers/default-helpers.rb', line 271

def month_pagename
  @month_pagename
end

Instance Method Details

#calendar_for(month) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/helpers/default-helpers.rb', line 287

def calendar_for( month )
  content = "<div class='calendar'>\n\n"
  content << "|_. Su |_. Mo |_. Tu |_. We |_. Th |_. Fr |_. Sa |\n"
  1.upto( time_for( month, 1 ).wday ) { content << "| . " }
  day = nil
  1.upto( 31 ) do |day_no|
    day = time_for( month, day_no )
    break if day.month > month
    content << "| [[ #{day_no} => #{day_pagename( day )} ]] "
    content << "|\n" if day.wday == 6
  end
  day.wday.upto( 5 ) { content << "| . " }
  content << "|\n"
  content << "\n\n#{month_pagename( month-1 )} #{month_pagename( month+1 )} \n"  
  content << "\n</div>"  
end

#render_coming_yearObject



279
280
281
# File 'lib/helpers/default-helpers.rb', line 279

def render_coming_year
  Time.now.month.upto( Time.now.month+12 ) { |m| render_month( m ) }
end

#render_month(month) ⇒ Object



283
284
285
# File 'lib/helpers/default-helpers.rb', line 283

def render_month( month )
  @wiki.revise( month_pagename( month  ), calendar_for( month ) , @author ) unless @wiki.exists?( month_pagename( month ) )
end

#time_for(month, day = 1) ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/helpers/default-helpers.rb', line 304

def time_for( month, day = 1 )
  year = Time.now.year
  if month > 12
    year +=1
    month -= 12
  elsif month < 1
    year -= 1
    month = month + 12
  end
  if day > 31
    month += 1
    day -= 31
  end
  Time.local( year, month, day, 8, 0 )
end