Class: BootswatchRails::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- BootswatchRails::Generators::InstallGenerator
- Defined in:
- lib/generators/bootswatch_rails/install/install_generator.rb
Instance Method Summary collapse
- #copy_directories ⇒ Object
- #setup_assets_precompile ⇒ Object
- #setup_head ⇒ Object
- #setup_layout ⇒ Object
- #update_application_controller ⇒ Object
- #update_application_css ⇒ Object
- #update_application_js ⇒ Object
Instance Method Details
#copy_directories ⇒ Object
122 123 124 125 126 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 122 def copy_directories directory "app", force: true directory "config" directory "lib", force: true end |
#setup_assets_precompile ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 111 def setup_assets_precompile return if .cdn == "none" initializer "bootswatch_assets.rb" do assets = "jquery.js" assets += " jquery-ui.js" if .ui? assets += " jquery.dataTables.js dataTables.responsive.js" if .dt? assets += " bootstrap.js" "Rails.application.config.assets.precompile += %w( #{assets} )" end end |
#setup_head ⇒ Object
128 129 130 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 128 def setup_head template "head.html.erb", "app/views/layouts/_head.html.erb" end |
#setup_layout ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 132 def setup_layout file = "app/views/layouts/application.html.erb" remove_file file template "#{.layout}.html.erb", file if .auth != "none" template "theme.html.erb", "app/views/layouts/_theme.html.erb" end end |
#update_application_controller ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 22 def update_application_controller file = "app/controllers/application_controller.rb" if .auth == "none" lines = [ "" ] elsif .auth == "sorcery" lines = [ "", " before_action :require_login" ] else lines = [ "", " before_action :authenticate_#{.auth}!" ] end lines += [ "", " private", "", " def default_theme", " BootswatchRails::THEMES[BootswatchRails::DEFAULT].to_s", " end", " helper_method :default_theme" ] if .auth != "none" lines += [ "", " def current_theme", " @current_theme = current_#{auth_resource}.theme if #{auth_check}", " @current_theme ||= default_theme", " end", " helper_method :current_theme" ] end if .auth == "sorcery" lines += [ "", " def not_authenticated", " redirect_to login_path, alert: t('sorcery.required')", " end" ] elsif .auth != "none" lines += [ "", " def after_sign_in_path_for(resource)", " session['#{auth_resource}_return_to'] || root_path", " end" ] end inject_into_file file, lines.join("\n"), after: /protect_from_forgery.*$/ end |
#update_application_css ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 99 def update_application_css if .cdn == "none" file = "app/assets/stylesheets/application.css" if .dt? inject_into_file file, before: /^.*require_self$/ do " *= require jquery.dataTables\n" + " *= require responsive.dataTables\n" end end end end |
#update_application_js ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 76 def update_application_js file = "app/assets/javascripts/application.js" unless .turbolinks? gsub_file file, /\/\/= require turbolinks\n/, '' end if .cdn == "none" inject_into_file file, after: /require jquery_ujs$/ do "\n//= require bootstrap" end if .ui? inject_into_file file, after: /require jquery$/ do "\n//= require jquery-ui" end end if .dt? inject_into_file file, before: /^\/\/= require_tree.*$/ do "//= require jquery.dataTables\n" + "//= require dataTables.responsive\n" end end end end |