Class: Spud::Events::CalendarBuilder

Inherits:
TableBuilder show all
Defined in:
lib/spud_events/calendar_builder.rb

Instance Method Summary collapse

Methods inherited from TableBuilder

#body, #body_r, #d, #h, #head, #head_r, #r

Constructor Details

#initialize(objects, template, calendar, options) ⇒ CalendarBuilder

Returns a new instance of CalendarBuilder.



4
5
6
7
8
# File 'lib/spud_events/calendar_builder.rb', line 4

def initialize(objects, template, calendar, options)
  super(objects, template, options)
  @calendar = calendar.new(options)
  @today = options[:today] || Time.now
end

Instance Method Details

#day(*args, &block) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spud_events/calendar_builder.rb', line 10

def day(*args,&block)
    raise ArgumentError, "Missing block" unless block_given?
    options = options_from_hash(args)
    day_method = options.delete(:day_method) || :start_at
    id_pattern = options.delete(:id)
    activity_class = options.delete(:activity)
    output = ""
    @calendar.objects_for_days(@objects, day_method).to_a.sort{|a1, a2| a1.first <=> a2.first }.each do |o|
        key, array = o
        day, objects = array
      
        output << @template.tag(:tr,options,true) if (day.wday ==  @calendar.first_weekday)
        output << @template.tag(:td,td_options(day, id_pattern, (objects.empty? ? nil: activity_class)), true)
        output << @template.with_output_buffer{block.call(day, objects)}
        output << '</td>'
        output << '</tr>' if (day.wday ==  @calendar.last_weekday)
    end
    @template.(:tbody, output.html_safe, {}, false)  
end