I have a calendar that shows public events of the month, it is a responsive layout, so I want to calculate the height of the week should be able. Therefore, I need to be able to calculate the number of weeks in a month, which includes partial weeks (weeks including the current month day and past / next month).
The following method is used to calculate the number of weeks in the month:
def weeks_in_month (on) @week_count = (0.5 + (date.end_of_month.day + date.beginning_of_month .wday) .to_f / 7.0) .round end
and & lt; Div & gt; The code to add the appropriate class (sas) for
is:
def weeks_agra weeks.map {| Week | Content_tag: div, category: week_slus (week) week.map {| Day | Day_cell (day)} .join.html_safe end} .join.html_Secure End DEF week_ class (date) class = ['week'] classes & lt; & Lt; "Wk_rows_4" if week_in_mon (date) == 4 squares & lt; & Lt; "Wk_rows_5" if week_in_mund (date) ==5 classes & lt; & Lt; "Wk_rows_6" if week_in_month (date) == 6 squares. Empty? ? Zero: classes ("") End
However, I have missed something. There is nothing other than the default 'Week'
class in the sections of the week.
It is based on Railscast # 213, which is amended according to the formation of a calendar without the table, whichever is heavily borrowed from RC # 231.
Any ideas why this & lt; Div & gt; Not specifying the correct class for
?
Everything in the calendar is working. Here is the full code:
Struct.new (: look ,: date ,: callback) title =% W [Monday Tuesday Wednesday Thursday Friday Saturday] START_DAY =: Sunday representatives: content_tag, to Visual def calendar_div content_tag 'div', id: "Calendar" header + week_ar end end def header content_tag 'div', id: 'workday' HEADER.map {| Day | Content_tag: div, category: 'day of the week' day end) .join.html_safe end-end def week_rows weeks.map {| Week | Content_tag: div, category: week_slus (week) week.map {| Day | Day_cell (day)} .join.html_safe end} .join.html_Secure End DEF week_ class (date) class = ['week'] classes & lt; & Lt; "Wk_rows_4" if week_in_mon (date) == 4 squares & lt; & Lt; "Wk_rows_5" if week_in_mund (date) ==5 classes & lt; & Lt; "Wk_rows_6" if week_in_month (date) == 6 squares. Empty? ? Zero: classes.join ( "") end def day_cell (day) content_tag: div, view.capture (day, & amp; callback), class: day_classes (day) end def day_classes (day) class = [ "day"] Classes & lt; & Lt; "Today" if day == date touts & lt; & Lt; "Nomant" if the day Month! = Date Month class & lt; & Lt; "Month" if the day Month == date Month classes ? Zero: classes.join ( "") end def week = date.beginning_of_month.beginning_of_week (START_DAY) last = date.end_of_month.end_of_week (START_DAY) (first..last) .to_a.in_groups_of (7) end def weeks_in_month (date ) @week_count = (0.5 + (date.end_of_month.day + date.beginning_of_month.wday) .to_f / 7.0) .round end end
OK, then take me some simple things to this solution:
def week_rows weeks.map {| week | Content_tag: div, class : week_classes do week.map {| day | Day_cell (day)} .join.html_safe end} .join.html_safe end def week_classes classes = [ 'weeks'] classes & lt; & lt; "Wk_rows_4" If Sptah_in_muth == 4 bridegroom If the week_in_moth ==5 classes << "Wk_rows_6" if week_in_moth ==6 squares? Empty?? Zero: classes.join ("") end def weeks_in_month (0.5 + (date.end_of_month.day + date.at_beginning_of_month.wday) .to_f / 7.0). finally the end
it wasn ' (Date)
parameter It is not necessary to pass in.
No comments:
Post a Comment