event_calendarに挑戦する

ガントチャートとかカレンダーにて「redMineのカレンダーを流用(ぱくり)する」という手法で使ったけど、プラグインで管理したいので何か探すことになった。

The Ruby Toolboxにてcalendarsカテゴリーがある。
Event calendar「Generates HTML event calendars」ってのを試してみよう
 

更新されていない?

Commit Historyを眺めると残念な感じがする。
 

インストール

Rails3なので

gem install event_calendar

とはやらない。
 
app_root/Gemfileに追記する

event_calendar

Aptanaのターミナルで

kenmituo@hoge ~/My Documents/Aptana Studio 3 Workspace/app_root
$ bundle install
(中略)
Installing event_calendar (0.0.2)

とかなる 
 
やっている途中でevent_calendar プラグインを使って Rails でイケてるカレンダーを実装してみたを発見して悲しくなったけどやり直し。
 

c:\>gem uninstall event_calendar
Successfully uninstalled event_calendar-0.0.2

app_root/Gemfileに追記した文をコメントアウト

#event_calendar

ターミナルで

$ bundle list
||< 
消えている。
 
app_root/Gemfileに追記した文を修正
>||
gem 'event-calendar', :require => 'event_calendar'

Aptanaのターミナルで

kenmituo@hoge ~/My Documents/Aptana Studio 3 Workspace/app_root
$ bundle
(中略)
Installing event_calendar (2.3.3)

ずいぶんとバージョンが上がったなー

kenmituo@hoge ~/My Documents/Aptana Studio 3 Workspace/app_root
$ bundle exec rails g event_calendar --use-jquery
Using JQuery for scripting
      create  public/javascripts/event_calendar.js
      create  public/stylesheets/event_calendar.css
      create  app/models/event.rb
      create  app/controllers/calendar_controller.rb
      create  app/views/calendar
      create  app/views/calendar/index.html.erb
      create  app/helpers/calendar_helper.rb
      create  db/migrate/20120905061400_create_events.rb
       route  match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calen
dar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}

今度は入った。いやっほー!
 

ファイルの検証

  • public/javascripts/event_calendar.js(jQueryで書いてある)
  • public/stylesheets/event_calendar.csscssだ。sccsはない)

/app_root/app/assetsに移動したい。

ここから大変そう

app/controllers/calendar_controller.rb

class CalendarController < ApplicationController
  def index
    @month = (params[:month] || (Time.zone || Time).now.month).to_i
    @year = (params[:year] || (Time.zone || Time).now.year).to_i
    @shown_month = Date.civil(@year, @month)
    @event_strips = Event.event_strips_for_month(@shown_month)
  end
end

「event_strips_for_month」これが何を指している?悩んだ結果は「イベントを月毎にするのはお前の役目だ!」に意訳された。
 
そうなると、ヘルパーとかの改造が必要なのか、、、面倒になってきたかな、、、
 
Display events of different ruby class typesというのを見つけて試すがうまくいかない、、、、やめよっかな。

kenmituo@hoge ~/My Documents/Aptana Studio 3 Workspace/app_root 
$ rails destroy event_calendar
Using Prototype for scripting
      remove  public/javascripts/event_calendar.js
      remove  public/stylesheets/event_calendar.css
      remove  app/models/event.rb
      remove  app/controllers/calendar_controller.rb
      remove  app/views/calendar
      remove  app/views/calendar/index.html.erb
      remove  app/helpers/calendar_helper.rb
      remove  db/migrate/20120905061400_create_events.rb
       route  match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calen
dar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}

やめた。
 

追記

やっぱりやめない。

bundle exec rails s

開始するときのコマンドを正しくやらないとダメと分かった。