Class: LaterDude::Calendar

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/later_dude/calendar.rb

Overview

TODO: Maybe make output prettier?

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month, options = {}, &block) ⇒ Calendar

Returns a new instance of Calendar.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/later_dude/calendar.rb', line 10

def initialize(year, month, options={}, &block)
  @year, @month = year, month
  @options = options.symbolize_keys.reverse_merge(self.class.default_calendar_options)

  # next_month and previous_month take precedence over next_and_previous_month
  @options[:next_month]     ||= @options[:next_and_previous_month]
  @options[:previous_month] ||= @options[:next_and_previous_month]

  @days = Date.civil(@year, @month, 1)..Date.civil(@year, @month, -1)
  @block = block
end

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



8
9
10
# File 'lib/later_dude/calendar.rb', line 8

def output_buffer
  @output_buffer
end

Class Method Details

.default_calendar_optionsObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/later_dude/calendar.rb', line 178

def default_calendar_options
  {
    :calendar_class => "calendar",
    :first_day_of_week => I18n.translate(:'date.first_day_of_week', :default => "0").to_i,
    :hide_day_names => false,
    :hide_month_name => false,
    :use_full_day_names => false,
    :current_month => I18n.translate(:'date.formats.calendar_header', :default => "%B"),
    :next_month => false,
    :previous_month => false,
    :next_and_previous_month => false,
    :yield_surrounding_days => false
  }
end

.weekend?(day) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/later_dude/calendar.rb', line 174

def weekend?(day)
  [0,6].include?(day.wday) # 0 = Sunday, 6 = Saturday
end

Instance Method Details

#to_htmlObject



22
23
24
25
26
# File 'lib/later_dude/calendar.rb', line 22

def to_html
  (:table, :class => "#{@options[:calendar_class]}") do
    (:thead, "#{show_month_names}#{show_day_names}".html_safe) + (:tbody, show_days)
  end
end