Skip to content

Commit

Permalink
Added --use-color option to the generator.
Browse files Browse the repository at this point in the history
Changed the way :all_day=true records are handled. They now set
:start_at and :end_at to 00:00:00 and 23:59:59 on their respective
days to facilitate better database interaction.

Updated the docs to reflect new installation and setup for Rails 3
beta. Also clarified some points with :color usage and :all_day usage.
  • Loading branch information
jamezilla committed Jun 26, 2010
1 parent be05f60 commit 861eeca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
39 changes: 31 additions & 8 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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
==Install Rails 2

script/plugin install git://github.com/elevation/event_calendar.git

Expand All @@ -29,6 +29,18 @@ You can change the default event model name (Event) and view name (Calendar) by

You can also pass in custom column names for the start and end fields.

==Install Rails 3 beta 4

rails plugin install git://github.com/elevation/event_calendar.git

To generate the necessary static files AND the example below:

rails generate event_calendar

Options:

rails generate event_calendar --help


==Generated Files

Expand All @@ -39,7 +51,9 @@ Make sure to include the stylesheet and javascript in your layout/view.
public/stylesheets/event_calendar.css
public/javascripts/event_calendar.js

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

====db/migrate/XXXX_create_events.rb

Expand All @@ -59,12 +73,21 @@ Unless the --static-only option is given, the following will be generated. Names
end
end

At minimum we need to have start_at and end_at fields. Altnernatively, you can configure the columns to be used by passing options to has_event_calendar.

If the '--use-all-day' option is passed to the generator, it will also add a boolean all_day field.

An event can also have a *color* field (hex value stored as a string) which determines the color of the event.
Or simply override the default virtual attribute on the model. For example, if events are associated to a calendar model, then the events can get their color from the calendar.
At minimum we need to have start_at and end_at fields. Altnernatively,
you can configure the columns to be used by passing options to
has_event_calendar.

If the '--use-all-day' option is passed to the generator, it will also
add a boolean all_day field. Set :start_at to be any time on the day
of the event and set :all_day to true. When :start_at and :end_at are
written to the database they are changed to 00:00:00 and 23:59:59
respectively.

An event can also have a *color* field (any string which is a valid
CSS color) which determines the color of the event. Or simply
override the default virtual attribute on the model. For example, if
events are associated to a calendar model, then the events can get
their color from the calendar.

====app/models/event.rb

Expand Down
16 changes: 14 additions & 2 deletions lib/event_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def has_event_calendar(options={})
self.end_at_field = ( options[:end_at_field] ||= :end_at ).to_s
alias_attribute :start_at, start_at_field unless start_at_field == 'start_at'
alias_attribute :end_at, end_at_field unless end_at_field == 'end_at'

before_save :adjust_all_day_dates
send :include, InstanceMethods
end

# For the given month, find the start and end dates
# Find all the events within this range, and create event strips for them
def event_strips_for_month(shown_date, first_day_of_week=0, find_options = {})
Expand Down Expand Up @@ -172,5 +172,17 @@ def clip_range(start_d, end_d)
end
[clipped_start, clipped_end]
end

def adjust_all_day_dates
if self[:all_day]
self[:start_at] = self[:start_at].beginning_of_day
if self[:end_at]
self[:end_at] = self[:end_at].beginning_of_day + 1.day - 1.second
else
self[:end_at] = self[:start_at].beginning_of_day + 1.day - 1.second
end
end
end

end
end
3 changes: 2 additions & 1 deletion lib/generators/event_calendar/event_calendar_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class EventCalendarGenerator < Rails::Generators::Base

class_option :static_only, :type => :boolean, :default => false, :desc => "Only generate stylesheets and scripts"
class_option :use_jquery, :type => :boolean, :default => false, :desc => "Use JQuery for scripting"
class_option :use_all_day, :type => :boolean, :default => false, :desc => "Add an additional all_day column to the database"
class_option :use_all_day, :type => :boolean, :default => false, :desc => "Add an additional 'all_day' attribute"
class_option :use_color, :type => :boolean, :default => false, :desc => "Add an additional 'color' attribute"
class_option :model_name, :type => :string, :default => "event", :desc => "Override the default model name"
class_option :controller_name, :type => :string, :default => "calendars", :desc => "Override the controller and view name"

Expand Down
7 changes: 5 additions & 2 deletions lib/generators/event_calendar/templates/migration.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ class Create<%= table_name.camelize %> < ActiveRecord::Migration
t.datetime :start_at
t.datetime :end_at
<%- if options[:use_all_day] -%>
t.boolean :all_day
t.boolean :all_day, :default => false
<%- end -%>

<%- if options[:use_color] -%>
t.string :color
<%- end -%>

t.timestamps
end
end
Expand Down

0 comments on commit 861eeca

Please sign in to comment.