Class: Popolo::Generators::PopoloGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/popolo_generator.rb

Overview

Run this generator once before using Popolo in your application.

Examples:

rails generate popolo

Instance Method Summary collapse

Instance Method Details

#add_rescue_from_block_to_application_controllerObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/popolo_generator.rb', line 17

def add_rescue_from_block_to_application_controller
  inject_into_class 'app/controllers/application_controller.rb', 'ApplicationController' do
    <<-EOS
  rescue_from Mongoid::Errors::DocumentNotFound do |exception|
    respond_to do |format|
format.html { render file: Rails.root.join('public', '404.html'), status: :not_found, layout: false }
format.json { head :not_found }
format.atom { head :not_found }
    end
  end
    EOS
  end
end

#add_routesObject



13
14
15
# File 'lib/generators/popolo_generator.rb', line 13

def add_routes
  route "mount Popolo::Engine => '/'"
end

#add_ruby_version_to_gemfileObject



31
32
33
# File 'lib/generators/popolo_generator.rb', line 31

def add_ruby_version_to_gemfile
  prepend_to_file 'Gemfile', "ruby '1.9.3'"
end

#show_readmeObject



35
36
37
# File 'lib/generators/popolo_generator.rb', line 35

def show_readme
  readme 'README' if behavior == :invoke
end