Repository URL to install this package:
|
Version:
4.1.0beta1 ▾
|
module Evergreen
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
def copy_templates
copy_file "home.html.erb", "app/views/pages/home.html.erb"
@model_name = 'Page'
template "evergreen.rb.erb",
"config/initializers/evergreen.rb"
template "page.rb.erb",
"app/models/page.rb"
template "show.html.erb",
"app/views/pages/show.html.erb"
template "page_spec.rb.erb",
"spec/models/page_spec.rb"
template "pages_controller.rb.erb",
"app/controllers/pages_controller.rb"
end
def setup_routes
["root :to => 'pages#home'",
"get '*path' => 'pages#show', :as => :page"].each do |routing_code|
log :route, routing_code
sentinel = %r(^end$)
in_root do
inject_into_file 'config/routes.rb',
"\n #{routing_code}\n",
{ :before => sentinel, :verbose => false }
end
end
end
def add_rescues
rescues = %q{ rescue_from 'StandardError', with: :server_error
rescue_from 'ActionView::MissingTemplate', with: :not_found
rescue_from 'ActiveRecord::RecordNotFound', with: :not_found}
sentinel = %r(^end$)
in_root do
inject_into_file 'app/controllers/application_controller.rb',
"\n#{rescues}\n",
{ :before => sentinel, :verbose => false }
end
end
def create_migrations
rake "evergreen:install:migrations"
end
end
end