Class: CalendarHelper::CalendarBuilder

Inherits:
TableHelper::TableBuilder show all
Defined in:
lib/ical/calendar_helper.rb

Instance Method Summary collapse

Methods inherited from TableHelper::TableBuilder

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

Constructor Details

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

Returns a new instance of CalendarBuilder.



23
24
25
26
27
28
# File 'lib/ical/calendar_helper.rb', line 23

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

Instance Method Details

#day(*args) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ical/calendar_helper.rb', line 30

def day(*args)
  raise ArgumentError, "Missing block" unless block_given?
  options = options_from_hash(args)
  day_method = options.delete(:day_method) || :date
  id_pattern = options.delete(:id) || 'day-%d'
  special_klass = options.delete(:special_klass) || nil

  # status
  tbody do
    @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
      status = objects.any? ? objects.collect {|o| o.try(:ical_klass) }.compact.join(" ") : "free"
      concat(tag(:tr, options, true)) if(day.wday ==  @calendar.first_weekday)
      if @row_header && day.wday ==  @calendar.first_weekday
        row_header_options = td_options(day, id_pattern)
        row_header_options[:class] ||= ""
        row_header_options[:class] << " row_header"
        concat(tag(:td, row_header_options, true))
        yield(day, nil)
        concat("</td>")
      end
      concat(tag(:td, td_options(day, id_pattern, status, special_klass), true))
      yield(day, objects)
      concat('</td>')
      concat('</tr>') if(day.wday ==  @calendar.last_weekday)
    end
  end
end