Class: Rambulance::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

:nodoc:



11
12
13
14
15
16
17
# File 'lib/generators/rambulance/install_generator.rb', line 11

def self.banner #:nodoc:
  <<-BANNER.chomp
rails g rambulance:install

    Copies all error partial templates and an initializer to your application.
BANNER
end

Instance Method Details

#copy_initializerObject

:nodoc:



40
41
42
43
# File 'lib/generators/rambulance/install_generator.rb', line 40

def copy_initializer #:nodoc:
  say "\n" "generating initializer:"
  template "rambulance.rb", "config/initializers/rambulance.rb"
end

#copy_layoutObject

:nodoc:



35
36
37
38
# File 'lib/generators/rambulance/install_generator.rb', line 35

def copy_layout #:nodoc:
  say "\ncopying app/views/layouts/application.html.#{template_engine} to app/views/layouts/error.html.#{template_engine}:"
  copy_file Rails.root.join("app/views/layouts/application.html.#{template_engine}"), "app/views/layouts/error.html.#{template_engine}"
end

#copy_templatesObject

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/rambulance/install_generator.rb', line 20

def copy_templates #:nodoc:
  say "generating templates:"
  filename_pattern = File.join(self.class.source_root, "views", "*.html.#{template_engine}")
  Dir.glob(filename_pattern).map {|f| File.basename f }.each do |f|
    copy_file "views/#{f}", "app/views/errors/#{f}"
  end

  if defined?(Jbuilder)
    filename_pattern = File.join(self.class.source_root, "views", "*.json.jbuilder")
    Dir.glob(filename_pattern).map {|f| File.basename f }.each do |f|
      copy_file "views/#{f}", "app/views/errors/#{f}"
    end
  end
end