Class: WeeklyCalendar::Calendar
- Inherits:
-
Object
- Object
- WeeklyCalendar::Calendar
- Defined in:
- lib/weekly_calendar/calendar.rb
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #content_tag(*args, &block) ⇒ Object
- #date_box(date) ⇒ Object
- #days ⇒ Object
- #events_ending_this_week(week, date) ⇒ Object
- #events_for_date(date) ⇒ Object
- #headings ⇒ Object
-
#initialize(options) ⇒ Calendar
constructor
A new instance of Calendar.
- #safe_str(&block) ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
5 6 7 |
# File 'lib/weekly_calendar/calendar.rb', line 5 def output_buffer @output_buffer end |
Class Method Details
.as_html(options) ⇒ Object
7 8 9 |
# File 'lib/weekly_calendar/calendar.rb', line 7 def self.as_html() self.new().to_html end |
Instance Method Details
#body ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/weekly_calendar/calendar.rb', line 51 def body content_tag :tr do String.new.html_safe.tap do |s| @days.each do |date| others = [ class: date_classes(date), :'data-date' => date.to_date ] s << content_tag(:td, date_box(date) + events_ending_this_week(days, date) + events_for_date(date), *others) end end end end |
#content_tag(*args, &block) ⇒ Object
104 105 106 |
# File 'lib/weekly_calendar/calendar.rb', line 104 def content_tag(*args, &block) @view.content_tag(*args, &block) end |
#date_box(date) ⇒ Object
64 65 66 |
# File 'lib/weekly_calendar/calendar.rb', line 64 def date_box(date) content_tag :div, date.mday, class: 'wc-date' end |
#days ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/weekly_calendar/calendar.rb', line 27 def days start_week = (@date - 1.week) if ![0,6].include?(@date.wday) # is a weekday start_week -= 1.week end if @options[:weekend] start_week.week else start_week.week[1..5] end end |
#events_ending_this_week(week, date) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/weekly_calendar/calendar.rb', line 83 def events_ending_this_week(week, date) unless (events = events_ending_on(date)).empty? content_tag :div, class: 'wc-events-ending' do safe_str do |s| events.compact.each do |event| next if event.start_at_date >= week.first.to_date s << render_event(event, on: date.to_date) end end end end end |
#events_for_date(date) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/weekly_calendar/calendar.rb', line 68 def events_for_date(date) events = @events.delete(date.to_date) return if events.nil? content_tag :div, class: 'wc-events' do safe_str do |s| events.each do |event| next if event.nil? s << render_event(event, on: date.to_date) end end end end |
#headings ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/weekly_calendar/calendar.rb', line 39 def headings content_tag :tr do String.new.html_safe.tap do |s| @days.each do |d| # @todo Localize the month/day order others = [ class: date_classes(d) ] s << content_tag(:th, "#{Date::ABBR_DAYNAMES[d.wday]} #{d.month}/#{d.mday}", *others) end end end end |
#safe_str(&block) ⇒ Object
100 101 102 |
# File 'lib/weekly_calendar/calendar.rb', line 100 def safe_str(&block) String.new.html_safe.tap(&block) end |
#to_html ⇒ Object
96 97 98 |
# File 'lib/weekly_calendar/calendar.rb', line 96 def to_html to_s.html_safe end |
#to_s ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/weekly_calendar/calendar.rb', line 19 def to_s @days = days content_tag :table, class: "weekly-calendar #{@options[:class]}", id: @options[:id] do content_tag(:thead, headings) + content_tag(:tbody, body) end end |