Repository URL to install this package:
Version:
0.2.0 ▾
|
module NeotericNews
class InstallGenerator < Rails::Generators::Base
desc "Installs Neoteric News and generates the necessary migrations"
include Rails::Generators::Migration
def self.source_root
@_neoteric_news_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/news_posts/show.html.erb"
copy_file "index.html.erb", "app/views/news_posts/index.html.erb"
copy_file "_news_post.html.erb", "app/views/news_posts/_news_post.html.erb"
copy_file "news_posts_controller.rb", "app/controllers/news_posts_controller.rb"
copy_file "news_post.rb", "app/models/news_post.rb"
copy_file "neoteric_news.rb", "config/initializers/neoteric_news.rb"
end
def configure_routes
route "get 'news/:year/:month/:id' => 'news_posts#show', :as => :news_post"
route %Q(resources :news_posts, :only => :index, :path => 'news' do
get ':year/:month' => 'news_posts#archive', :on => :collection, :as => :archive
end)
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