<commit_before>==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.

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

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

To generate the necessary static files AND the example below:

  script/generate event_calendar

Options:

* --static-only: Only generate the stylesheet and javascript
* --use-jquery: Generate jquery javascript
* --use-all-day: Include an 'all_day' field on events, and display appropriately

You can change the default event model name (Event) and view name (Calendar) by passing in two name arguments:

  script/generate event_calendar EventModel ViewName
  
You can change the start_at and end_at columns for you existing event model by supplying the following parameters:

====app/models/event.rb
  
  class Event < ActiveRecord::Base
    has_event_calendar :start_at_field  => 'custom_start_at', :end_at_field => 'custom_end_at'
  end


==Generated Files

Make sure to include the stylesheet and javascript in your layout/view.

====Static files

  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.

====db/migrate/XXXX_create_events.rb

  class CreateEvents < ActiveRecord::Migration
    def self.up
      create_table :events do |t|
        t.string :name
        t.datetime :start_at
        t.datetime :end_at

        t.timestamps
      end
    end

    def self.down
      drop_table :events
    end
  end
  
At minimum we need to have start_at and end_at fields.

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.

====app/models/event.rb
  
  class Event < ActiveRecord::Base
    has_event_calendar
  end

====config/routes.rb

  map.calendar "/calendar/:year/:month", :controller => "calendar", :action => "index", :year => Time.now.year, :month => Time.now.month

====app/controllers/calendar_controller.rb
  
  class CalendarController < ApplicationController

    def index
      @month = params[:month].to_i
      @year = params[:year].to_i

      @shown_month = Date.civil(@year, @month)

      @event_strips = Event.event_strips_for_month(@shown_month)
    end

  end

====app/helpers/calendar_helper.rb

Some helper methods are created, but you could put this in the view. The key is our calendar method, which takes some options.

  module CalendarHelper
    def month_link(month_date)
      link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year})
    end
  
    # custom options for this calendar
    def event_calendar_options
      { 
        :year => @year,
        :month => @month,<commit_msg>Add Philip's changes to the README.<commit_after>==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.

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

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

To generate the necessary static files AND the example below:

  script/generate event_calendar

Options:

* --static-only: Only generate the stylesheet and javascript
* --use-jquery: Generate jquery javascript
* --use-all-day: Include an 'all_day' field on events, and display appropriately

You can change the default event model name (Event) and view name (Calendar) by passing in two name arguments:

  script/generate event_calendar EventModel ViewName
  
You can also pass in custom column names for the start and end fields.


==Generated Files

Make sure to include the stylesheet and javascript in your layout/view.

====Static files

  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.

====db/migrate/XXXX_create_events.rb

  class CreateEvents < ActiveRecord::Migration
    def self.up
      create_table :events do |t|
        t.string :name
        t.datetime :start_at
        t.datetime :end_at

        t.timestamps
      end
    end

    def self.down
      drop_table :events
    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.

====app/models/event.rb
  
  class Event < ActiveRecord::Base
    has_event_calendar

    # To specify the columns to use call it like this:
    # 
    # has_event_calendar :start_at_field  => 'custom_start_at', :end_at_field => 'custom_end_at'
    # 

  end

====config/routes.rb

  map.calendar "/calendar/:year/:month", :controller => "calendar", :action => "index", :year => Time.now.year, :month => Time.now.month

====app/controllers/calendar_controller.rb
  
  class CalendarController < ApplicationController

    def index
      @month = params[:month].to_i
      @year = params[:year].to_i

      @shown_month = Date.civil(@year, @month)

      @event_strips = Event.event_strips_for_month(@shown_month)
  
      # To restrict what events are included in the result you can pass additional find options like this:
      #
      # @event_strips = Event.event_strips_for_month(@shown_month, :include => :some_relation, :conditions => 'some_relations.some_column = true')
      #

    end

  end

====app/helpers/calendar_helper.rb

Some helper methods are created, but you could put this in the view. The key is our calendar method, which takes some options.

  module CalendarHelper
    def month_link(month_date)
      link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year})
    end
  
    # custom options for this calendar
    def event_calendar_options
      { 
        :year => @year,
        :month => @month,
{'fraction_non_alphanumeric': 0.0829644438097958, 'fraction_numerical': 0.002570327002713123, 'mean_word_length': 3.632275132275132, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7264379', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1946, 'n_words': 747}