Module: CalendarViewHelper
- Defined in:
- app/helpers/calendar_view_helper.rb
Instance Method Summary collapse
- #calendar_square(options = {}) ⇒ Object
- #calendar_window(options = {}) ⇒ Object
- #color_follow_day(today, follow_day, highlight) ⇒ Object
- #wdays_names(first_wday) ⇒ Object
Instance Method Details
#calendar_square(options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/helpers/calendar_view_helper.rb', line 82 def calendar_square(={}) now = DateTime.now month = [:month] ? [:month] : now.month year = [:year] ? [:year] : now.year month_delta = [:month_delta] ? [:month_delta] : 0 year_delta = [:year_delta] ? [:year_delta] : 0 highlight = [:highlight_date] ? [:highlight_date] : nil if [:highlight_day] && [:highlight_month] && [:highlight_year] highlight = Date.new([:highlight_year],[:highlight_month],[:highlight_day]) end highlight = [:highlight_between] if [:highlight_between] month = month + month_delta year = year + year_delta delta = month.divmod(12) if delta[1].zero? year = year + delta[0] -1 month = 12 else year = year + delta[0] month = delta[1] end first_wday = [:first_wday] == 0 ? 0 : 1 last_wday = first_wday == 0 ? 6 : 0 first = Date.new(year,month,1) last = Date.new(year,month,-1) today = Date.new(now.year,now.month,now.day) html = "" html << "<div class=\"calendar square\">" html << "<h3 class=\"monthname\">" html << t(:month_names,:scope=>:date)[month] html << " #{year}" if year != now.year html << "</h3>" html << "<div class=\"content\">" html << "<table>" html << "<tr><td class=\"corner\"> </td>" html << wdays_names(first_wday) html << "</tr>" if first.wday != first_wday (first_wday == 0 ? (first.wday == 0 ? 7 : first.wday) : (first.wday == 0 ? 7 : first.wday) - 1).downto(1) do |i| prev = first - i if prev.wday == first_wday html << "<tr>" html << "<td class=\"weeknum\">#{prev.cweek}</td>" end html << "<td class=\"outside\">#{prev.day}</td>" end end (first.day).upto(last.day) do |i| follow_day = Date.new(year,month,i) if follow_day.wday == first_wday html << "<tr>" html << "<td class=\"weeknum\">#{follow_day.cweek}</td>" end html << color_follow_day(today,follow_day,highlight) if follow_day.wday == last_wday html << "</tr>" end end if last_wday != last.wday 1.upto(7-(first_wday == 0 ? last.wday+1 : last.wday)) do |i| post = last + i html << "<td class=\"outside\">#{post.day}</td>" end end html << "</tr>" html << "</table></div></div>" html.html_safe end |
#calendar_window(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/calendar_view_helper.rb', line 20 def calendar_window(={}) html = "" now = DateTime.now year = now.year month = now.month back = [:back] ? [:back] : 10 forward = [:forward] ? [:forward] : 20 highlight = [:highlight_date] ? [:highlight_date] : nil if [:highlight_day] && [:highlight_month] && [:highlight_year] highlight = Date.new([:highlight_year],[:highlight_month],[:highlight_day]) end highlight = [:highlight_between] if [:highlight_between] fday = Date.new(now.year,now.month,now.day) nowday = Date.new(now.year,now.month,now.day) fday -= back wdays = [] days = [] weeks = [] months = [] colspan = 1 mcolspan = 1 html = "" html << "<div class=\"calendar window\">" html << "<h3>#{[:title]}</h3>" if [:title] html << "<div class=\"content\">" html << "<table>" 1.upto(back + forward) do if fday == Date.new(fday.year,fday.month,-1) months << "<td class=\"monthnum\" colspan=\""+mcolspan.to_s+"\">"+fday.month.to_s+"</td>" mcolspan=1 else mcolspan+=1 end if fday.wday == 0 weeks << "<td class=\"weeknum\" colspan=\""+colspan.to_s+"\">"+fday.cweek.to_s+"</td>" colspan=1 else colspan+=1 end wdays << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[fday.wday == 7 ? 0 : fday.wday]}</td>" days << color_follow_day(nowday,fday,highlight) fday = fday + 1 end months << "<td class=\"monthnum\" colspan=\""+mcolspan.to_s+"\">"+fday.month.to_s+"</td>" weeks << "<td class=\"weeknum\" colspan=\""+colspan.to_s+"\">"+fday.cweek.to_s+"</td>" html << "<tr>" html << months.join html << "</tr>" html << "<tr>" html << weeks.join html << "</tr>" html << "<tr>" html << wdays.join html << "</tr>" html << "<tr>" html << days.join html << "</tr>" html << "</table></div></div>" html.html_safe end |
#color_follow_day(today, follow_day, highlight) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'app/helpers/calendar_view_helper.rb', line 3 def color_follow_day(today,follow_day,highlight) day = follow_day.day c = "" c << "this " if (highlight.class.eql?(Range) && highlight.include?(follow_day)) || follow_day == highlight c << "today " if follow_day == today c << "weekend " if [0,6].include?(follow_day.wday) "<td class=\"#{c}\">#{day}</td>" end |
#wdays_names(first_wday) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/helpers/calendar_view_helper.rb', line 12 def wdays_names(first_wday) html = "" first_wday.upto(first_wday+6) do |i| html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[i == 7 ? 0 : i]}</td>" end html end |