Skip to content

Commit

Permalink
Complete rewrite of the calendar's HTML generation and styling. Can a…
Browse files Browse the repository at this point in the history
…rbitrarily set the calendar width. See the CHANGELOG for more info.
  • Loading branch information
jeffschuil committed Nov 24, 2009
1 parent 7750207 commit 4cf57a8
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 340 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rdoc
@@ -0,0 +1,13 @@
== 2009-11-23 / Version 2
* Complete rewrite of the calendar's HTML generation and styling
* Event rows are now table cells which span the desired number of columns
* The width can be set arbitrarily, or it can be left to resize with the containing element
* Removes the use of background images for displaying the grid
* Increased ability to style calendar days
* Removed legacy options, comments, and code
* Caution, not backwards compatible with some of Version 1's options

== 2009-11-11 / Version 1
* The initial EventCalendar Rails Plugin
* Most bugs and issues have been resolved
* Works, but isn't as flexible as desired
85 changes: 43 additions & 42 deletions README.rdoc
@@ -1,12 +1,13 @@
==EventCalendar

Easily show multiple, overlapping events across calendar days and rows.
See http://dev.elevationblog.com/2009/7/23/event-calendar-rails-plugin for a screenshot.

Based off of James Urquhart's http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/ which in turn is based on Geoffrey Grosenbach's CalendarHelper.
See http://dev.elevationblog.com/2009/7/23/event-calendar-rails-plugin for a screenshot.

After install, the "calendar" method will be available within your views.

To customize the look, modify the included stylesheet and/or change the default options.


==Install

Expand All @@ -18,7 +19,7 @@ To generate the necessary static files AND the example below:

Options:

* --static-only: Only generate the stylesheet, javascript, and sample bg grid images
* --static-only: Only generate the stylesheet and javascript
* --use-jquery: Generate jquery javascript

You can change the default event model name (Event) and view name (Calendar) by passing in two name arguments:
Expand All @@ -34,9 +35,6 @@ Make sure to include the stylesheet and javascript in your layout/view.

public/stylesheets/event_calendar.css
public/javascripts/event_calendar.js
public/images/event_calendar
public/images/event_calendar/85_bg.gif
public/images/event_calendar/120_bg.gif

Unless the --static-only option is given, the following will be generated. Names will differ if name arguments were passed to the generator.

Expand Down Expand Up @@ -111,7 +109,7 @@ Some helper methods are created, but you could put this in the view. The key is

def event_calendar
calendar event_calendar_options do |event|
"<a href='/events/#{event.id}' title=\"#{h(event.name)}\"><div>#{h(event.name)}</div></a>"
%(<a href="/events/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
end
end
end
Expand All @@ -132,32 +130,50 @@ The default options for the calendar are:
defaults = {
:year => Time.zone.now.year,
:month => Time.zone.now.month,
:table_class => 'calendar',
:month_name_class => 'monthName',
:other_month_class => 'otherMonth',
:day_name_class => 'dayName',
:day_class => 'day',
:abbrev => (0..2),
:first_day_of_week => 0, # See note below when setting this
:accessible => false,
:show_today => true,
:month_name_text => Time.zone.now.strftime("%B %Y"),
:previous_month_text => nil,
:next_month_text => nil,
:start => nil,
:event_strips => [],
:event_width => 85,

# it would be nice to have these in the CSS file
# but they are needed to perform height calculations
:width => nil,
:height => 500,
:day_names_height => 18,
:day_nums_height => 18,
:event_height => 18,
:min_height => 70,
:event_margin => 2,
:event_margin => 1,
:event_padding_top => 1,

:use_javascript => true,
:link_to_day_action => false
}

You can override any of these by passing your options to the calendar method. In the above eample, update the event_calendar_options helper method.
You can override any of these by passing your options to the calendar method. In the above example, update the event_calendar_options helper method.

====Details

* See the notes in the plugin's calendar_helper.rb for more info.

* *width*: Optional, if none is given it will stretch to the containing element.

* *height*: Defaults to 500px. This is the approx minimum total height of the calendar. It could be greater if a calendar row(s) need to stretch to fit additional events.

* *use_javascript*: If you set it to false, cleaner HTML will be output, without inline Javascript, but events spanning multiple days will not be displayed correctly. This option should therefore only be used if your calendar uses only single-day events.

* *link_to_day_action*: Will make the calendar's day numbers links to the given Rails action. Note, you'll probably want a corresponding route, controller action, and view to go with this action. Example:

Helper/View calendar option:
:link_to_day_action => "day"

Route (the controller is the same as your other calendar route):
map.calendar_day "/calendar/:year/:month/:day", :controller => "calendar", :action => "day"


==NOTES
==Notes

* If you want to change the <b>first day of the week</b> from the default of Sunday (0), then set the new value in an instance variable and pass it to event_strips_for_month (in the controller), and to the event calendar options (in the helper/view).

Expand All @@ -175,33 +191,18 @@ You can override any of these by passing your options to the calendar method. In
@event_strips = Event.create_event_strips(start_d, end_d, @events)

* The event <b>select color</b> is set in the event_calendar.js file.

====Options

* *event_width*: You will need to change the .calendar background-image in the CSS file. There are two images included:
* 85px
* 120px

* *use_javascript*: If you set it to false, cleaner HTML will be output, without inline Javascript, but events spanning multiple days will not be displayed correctly. This option should therefore only be used if your calendar uses only single-day events.


* *link_to_day_action*: Will make the calendar's day numbers links to the given Rails action. Note, you'll probably want a corresponding route, controller action, and view to go with this action. Example:

Helper/View calendar option:
:link_to_day_action => "day"

Route (the controller is the same as your other calendar route):
map.calendar_day "/calendar/:year/:month/:day", :controller => "calendar", :action => "day"


==Contributors

==TODO

Add tests!

* Jeff Schuil
* See commit history for list of additional contributors.
* Thanks to those who have added features, fixed bugs, and/or reported issues.

==Contributors
== History

Jeff Schuil
* Though EventCalendar has diverged greatly, it was...
* Originally based off of James Urquhart's http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
* This in turn started as Geoffrey Grosenbach's CalendarHelper.

Copyright (c) 2009 Elevation, released under the MIT license
3 changes: 0 additions & 3 deletions generators/event_calendar/USAGE
Expand Up @@ -7,9 +7,6 @@ Usage:
# static files
public/stylesheets/event_calendar.css
public/javascripts/event_calendar.js
public/images/event_calendar
public/images/event_calendar/85_bg.gif
public/images/event_calendar/120_bg.gif

# Unless --static-only option is given
# MVC and supporting files (depending on model and view name)
Expand Down
4 changes: 0 additions & 4 deletions generators/event_calendar/event_calendar_generator.rb
Expand Up @@ -20,10 +20,6 @@ def manifest
script = options[:use_jquery] ? 'jq_javascript.js' : 'javascript.js'
m.file script, "public/javascripts/event_calendar.js"

m.directory "public/images/event_calendar"
m.file "85_bg.gif", "public/images/event_calendar/85_bg.gif"
m.file "120_bg.gif", "public/images/event_calendar/120_bg.gif"

# MVC and other supporting files
unless options[:static_only]
m.template "model.rb.erb", File.join("app/models", "#{@class_name}.rb")
Expand Down
Binary file removed generators/event_calendar/templates/120_bg.gif
Binary file not shown.
Binary file removed generators/event_calendar/templates/85_bg.gif
Binary file not shown.
2 changes: 1 addition & 1 deletion generators/event_calendar/templates/helper.rb.erb
Expand Up @@ -17,7 +17,7 @@ module <%= view_name.classify %>Helper

def event_calendar
calendar event_calendar_opts do |event|
"<a href='/events/#{event.id}' title=\"#{h(event.name)}: #{event.start_at} to #{event.end_at}\"><div>#{h(event.name)}</div></a>"
%(<a href="/events/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
end
end
end

0 comments on commit 4cf57a8

Please sign in to comment.