Class: CalendarHelper::CalendarBuilder

Inherits:
TableHelper::TableBuilder show all
Defined in:
lib/table_builder/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.



24
25
26
27
28
29
# File 'lib/table_builder/calendar_helper.rb', line 24

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)


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
# File 'lib/table_builder/calendar_helper.rb', line 31

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)
  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
      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), true))
      yield(day, objects)
      concat('</td>')
      concat('</tr>') if(day.wday ==  @calendar.last_weekday)
    end
  end
end