-
-
Save advorak/2760681 to your computer and use it in GitHub Desktop.
Revisions
-
advorak revised this gist
May 25, 2012 . 5 changed files with 91 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ // Place all the styles related to the home controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ #monthName { text-align: center; position: absolute; top: 0; display: inline; a { text-decoration: none; color: blue; &:hover { color: red; text-decoration: underline; } } } table.calendar { margin-top: 5em; th { background-color: lightgrey; } td { font-family: Georgia, serif; text-align: right; vertical-align: top; width: 100px; height: 100px; &span.day { position: relative; top: 0.5em; right: 0.5em; margin-top: 2em; font-size: 1.5em; } &.weekend { background-color: lightgrey; } &.today { background-color: yellow; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ $ -> tableWidth = $('table').width() $('h1#monthName').css('width',tableWidth) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,17 @@ class HomeController < ApplicationController def index current_year = (params[:year ] || Date.today.year ) current_month = (params[:month] || Date.today.month) @current_date = "#{current_year}-#{current_month}-#{Date.today.day}".to_date @days_in_month = [] @days_in_month[@current_date.beginning_of_month.wday] = (@current_date.beginning_of_month..@current_date.end_of_month).to_a @days_in_month = @days_in_month.flatten.in_groups_of(7, false) @beginning_of_month_blanks_count = @current_date.beginning_of_month.wday @days_in_month[0].compact! @end_of_month_blanks_count = (6 - @current_date.end_of_month.wday) puts @days_in_month.inspect end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ module HomeHelper def multiclass(*args) if args[0].is_a?(Hash) args[0] = args[0].to_a.collect do |key,value| key.to_s if value end.compact end args.join(" ") end def root_path_month_year(math) date = @current_date + math root_path(month: date.month, year: date.year) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,12 @@ %h1#monthName = link_to raw("«"), root_path_month_year(-1.month) = @current_date.strftime("%B") = link_to raw("»"), root_path_month_year(1.month) = link_to raw("«"), root_path_month_year(-1.year) = @current_date.strftime("%Y") = link_to raw("»"), root_path_month_year(1.year) %table.calendar{border: 1} %tr - Date::DAYNAMES.each do |day_of_week| %th= day_of_week @@ -7,8 +15,9 @@ - if @beginning_of_month_blanks_count > 0 && index == 0 %td{colspan: @beginning_of_month_blanks_count} - week.each do |date| %td{class: multiclass(today: date.today?, weekend: (date.sunday? || date.saturday?))} %span.day=raw date ? date.day : " " - if index == (@days_in_month.count) %td{colspan: @end_of_month_blanks_count} -
advorak revised this gist
May 21, 2012 . 2 changed files with 14 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,12 @@ class HomeController < ApplicationController def index @today = Date.today @days_in_month = [] @days_in_month[@today.beginning_of_month.cwday] = (@today.beginning_of_month.day..@today.end_of_month.day).to_a @days_in_month = @days_in_month.flatten.in_groups_of(7, false) @beginning_of_month_blanks_count = @today.beginning_of_month.cwday @beginning_of_month_blanks_count.times { @days_in_month[0].shift } @end_of_month_blanks_count = (6 - @today.end_of_month.cwday) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,14 @@ %table{border: 1} %tr - Date::DAYNAMES.each do |day_of_week| %th= day_of_week - @days_in_month.each_with_index do |week,index| %tr - if @beginning_of_month_blanks_count > 0 && index == 0 %td{colspan: @beginning_of_month_blanks_count} - week.each do |day| %td{style: (day == @today.day && "background-color: yellow;")}=raw day ? day : " " - if index == (@days_in_month.count - 1) %td{colspan: @end_of_month_blanks_count} -
advorak revised this gist
May 21, 2012 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ %h1 Home#index %p Find me in app/views/home/index.html.haml %table{border: 1} %tr - Date::DAYNAMES.each do |day_of_week| @@ -6,4 +9,4 @@ - @days_in_month.each do |week| %tr - week.each do |day| %td{style: (day == @today.day && "background-color: yellow;")}=raw day ? day : " " -
advorak revised this gist
May 21, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ class HomeController < ApplicationController def index @today = Date.today @days_in_month = [] @days_in_month[@today.beginning_of_month.cwday] = (1..@today.end_of_month.day).to_a @days_in_month = @days_in_month.flatten.in_groups_of(7) end end -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class HomeController < ApplicationController def index @today = Date.today @days_in_month = [] @days_in_month[@today.beginning_of_month.cwday] = (@today.beginning_of_month.day..@today.end_of_month.day).to_a @days_in_month = @days_in_month.flatten.in_groups_of(7) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ %table{border: 1} %tr - Date::DAYNAMES.each do |day_of_week| %th= day_of_week %tr - @days_in_month.each do |week| %tr - week.each do |day| %td=raw day ? day : " "