Module: CalendarHelper

Defined in:
lib/table_builder/calendar_helper.rb

Defined Under Namespace

Classes: Calendar, CalendarBuilder

Instance Method Summary collapse

Instance Method Details

#calendar_for(objects, *args) ⇒ Object

Generates a calendar (as a table) for an array of objects placing each of them on the corresponding date.

**TODO: fully document this method, the current documentation is far from done.**

Parameters:

  • options (Hash)

    extra options

    :row_header if true, each row will have an extra cell at the beginning, as a row header. A typical usage would be to output week numbers. When the block is called, it will get the date that would normally be passed to the first day of the week (to give you some context) and a nil list of objects (and that’s how you recognize it as a header, because empty days get an empty array, not nil).

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'lib/table_builder/calendar_helper.rb', line 12

def calendar_for(objects, *args)
  raise ArgumentError, "Missing block" unless block_given?
  options = args.last.is_a?(Hash) ? args.pop : {}
  html_options = options[:html]
  builder = options[:builder] || CalendarBuilder
  calendar = options[:calendar] || Calendar
  (:table, nil, html_options) do
    yield builder.new(objects || [], self, calendar, options)
  end
end