Class: DeviseAuthy::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- DeviseAuthy::Generators::InstallGenerator
- Defined in:
- lib/generators/devise_authy/install_generator.rb
Overview
Install Generator
Instance Method Summary collapse
- #add_configs ⇒ Object
- #copy_assets ⇒ Object
- #copy_locale ⇒ Object
- #copy_views ⇒ Object
- #inject_assets_in_layout ⇒ Object
Instance Method Details
#add_configs ⇒ Object
12 13 14 15 16 17 |
# File 'lib/generators/devise_authy/install_generator.rb', line 12 def add_configs inject_into_file "config/initializers/devise.rb", "\n" + " # ==> Devise Authy Authentication Extension\n" + " # How long should the user's device be remembered for.\n" + " # config.authy_remember_device = 1.month\n\n", :before => /^end[\r\n]*$/ end |
#copy_assets ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/generators/devise_authy/install_generator.rb', line 35 def copy_assets if .sass? copy_file '../../../app/assets/stylesheets/devise_authy.sass', 'app/assets/stylesheets/devise_authy.sass' else copy_file '../../../app/assets/stylesheets/devise_authy.css', 'app/assets/stylesheets/devise_authy.css' end copy_file '../../../app/assets/javascripts/devise_authy.js', 'app/assets/javascripts/devise_authy.js' end |
#copy_locale ⇒ Object
19 20 21 |
# File 'lib/generators/devise_authy/install_generator.rb', line 19 def copy_locale copy_file "../../../config/locales/en.yml", "config/locales/devise.authy.en.yml" end |
#copy_views ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/devise_authy/install_generator.rb', line 23 def copy_views if .haml? copy_file '../../../app/views/devise/enable_authy.html.haml', 'app/views/devise/devise_authy/enable_authy.html.haml' copy_file '../../../app/views/devise/verify_authy.html.haml', 'app/views/devise/devise_authy/verify_authy.html.haml' copy_file '../../../app/views/devise/verify_authy_installation.html.haml', 'app/views/devise/devise_authy/verify_authy_installation.html.haml' else copy_file '../../../app/views/devise/enable_authy.html.erb', 'app/views/devise/devise_authy/enable_authy.html.erb' copy_file '../../../app/views/devise/verify_authy.html.erb', 'app/views/devise/devise_authy/verify_authy.html.erb' copy_file '../../../app/views/devise/verify_authy_installation.html.erb', 'app/views/devise/devise_authy/verify_authy_installation.html.erb' end end |
#inject_assets_in_layout ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/devise_authy/install_generator.rb', line 44 def inject_assets_in_layout { :haml => { :before => %r{%body\s*$}, :content => %@ =javascript_include_tag "https://www.authy.com/form.authy.min.js" =stylesheet_link_tag "https://www.authy.com/form.authy.min.css" =javascript_include_tag "devise_authy.js" @ }, :erb => { :before => %r{\s*</\s*head\s*>\s*}, :content => %@ <%=javascript_include_tag "https://www.authy.com/form.authy.min.js" %> <%=stylesheet_link_tag "https://www.authy.com/form.authy.min.css" %> <%=javascript_include_tag "devise_authy.js" %> @ } }.each do |extension, opts| file_path = "app/views/layouts/application.html.#{extension}" if File.exists?(file_path) && !File.read(file_path).include?("devise_authy.js") inject_into_file(file_path, opts.delete(:content), opts) end end end |