Class: CalendarHelper::CalendarBuilder
- Inherits:
-
TableHelper::TableBuilder
- Object
- TableHelper::TableBuilder
- CalendarHelper::CalendarBuilder
- Defined in:
- lib/table_builder/calendar_helper.rb
Instance Method Summary collapse
- #day(options = {}) ⇒ Object
-
#initialize(objects, template, calendar, options) ⇒ CalendarBuilder
constructor
A new instance of CalendarBuilder.
- #td_options(day, objects, id_pattern) ⇒ Object
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.
11 12 13 14 15 |
# File 'lib/table_builder/calendar_helper.rb', line 11 def initialize objects, template, calendar, @calendar = calendar.new() @today = [:today] || Time.now super objects, template, end |
Instance Method Details
#day(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/table_builder/calendar_helper.rb', line 17 def day = {} raise ArgumentError, "Missing block" unless block_given? day_method = .delete(:day_method) || :date id_pattern = .delete(:id) tag(:tbody) do output = '' @calendar.objects_for_days(@objects, &day_method).each_slice(7) do |week| output = r do week.map do |day, objects| d capture{yield day, objects}, (day, objects, id_pattern) end end end output end end |
#td_options(day, objects, id_pattern) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/table_builder/calendar_helper.rb', line 36 def day, objects, id_pattern = {} css = [] css << 'notmonth' if day.month != @calendar.month css << 'today' if @today == day css << 'weekend' if day.wday == 0 or day.wday == 6 # css << 'empty' if objects.empty? [:class] = css.join(' ') [:id] = day.strftime(id_pattern) if id_pattern .delete_if{ |k,v| v.blank? } end |