Class: Flashee::Generators::Install::BootstrapGenerator

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

Overview

Houses the logic to install flashee into the target rails app using the bootstrap CSS framework. BootstrapGenerator translates to the ‘flashee:install:bootstrap

Instance Method Summary collapse

Instance Method Details

#copy_helperObject

Copies lib/templates/flashee_bootstrap_helper.rb into app/helpers/flashee_helper.rb.



9
10
11
12
13
14
# File 'lib/generators/flashee/install/bootstrap_generator.rb', line 9

def copy_helper
  helper_source = File.join(Gem.loaded_specs["flashee"].full_gem_path, "lib", "templates", "flashee_bootstrap_helper.rb")
  helper_target = File.join(Rails.root, "app", "helpers", "flashee_helper.rb")

  FileUtils.cp_r helper_source, helper_target
end

#copy_partialObject

Copies lib/templates/_flash_messages.html.erb to app/views/partials/_flash_messages.html.erb, will also create app/partials if it doesn’t exist already.



18
19
20
21
22
23
24
# File 'lib/generators/flashee/install/bootstrap_generator.rb', line 18

def copy_partial
  view_partial_source = File.join(Gem.loaded_specs["flashee"].full_gem_path, "lib", "templates", "_flash_messages.html.erb")
  view_partial_target = File.join(Rails.root, "app", "views", "partials", "_flash_messages.html.erb")

  FileUtils::mkdir_p  File.join(Rails.root, "app", "views", "partials")
  FileUtils.cp_r view_partial_source, view_partial_target
end

#print_post_install_infoObject

After installation completes, print the ERB snippet to the command line.



27
28
29
30
31
32
33
34
35
# File 'lib/generators/flashee/install/bootstrap_generator.rb', line 27

def print_post_install_info
  puts "==================================================================="
  puts "# One more step to go, To render the                              #"
  puts "# flash messages, you will need to add                            #"
  puts "# this line to application.html.erb.                              #"
  puts "#                                                                 #"
  puts '# <%= render partial: "partials/flash_messages", flash: flash %>  #'
  puts "==================================================================="
end