Repository URL to install this package:
|
Version:
0.2.2 ▾
|
module NeotericEvents
class InstallGenerator < Rails::Generators::Base
desc "Installs Neoteric Events and generates the necessary migrations"
include Rails::Generators::Migration
def self.source_root
@_neoteric_events_source_root ||= File.expand_path("../templates", __FILE__)
end
def self.next_migration_number(dirname)
Time.now.strftime("%Y%m%d%H%M%S")
end
def copy_templates
copy_file "show.html.erb", "app/views/events/show.html.erb"
copy_file "index.html.erb", "app/views/events/index.html.erb"
copy_file "_event.html.erb", "app/views/events/_event.html.erb"
copy_file "_sidebar.html.erb", "app/views/events/_sidebar.html.erb"
end
def copy_classes
copy_file "events_controller.rb", "app/controllers/events_controller.rb"
copy_file "event.rb", "app/models/event.rb"
end
def setup_routes
route <<-ROUTES
resources :events, :only => [:index, :show] do
collection do
get ':year/:month', :to => 'events#archive', :as => 'archive'
end
end
ROUTES
end
def create_migrations
Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
name = File.basename(filepath)
migration_template "migrations/#{name}", "db/migrate/#{name.gsub(/^\d+_/,'')}"
sleep 1
end
rake("db:migrate db:test:prepare")
end
end
end