class Layout::Generators::InstallGenerator
Attributes
app_name[R]
Public Instance Methods
add_forms_stylesheet()
click to toggle source
# File lib/generators/layout/install/install_generator.rb, line 71 def add_forms_stylesheet return unless (File.exists?('config/initializers/devise.rb') or File.exists?('config/initializers/omniauth.rb')) dir = File.expand_path("../templates", __FILE__) case framework_name when 'none' # TODO when 'simple' # TODO when 'bootstrap2' # TODO when 'bootstrap3' append_file 'app/assets/stylesheets/1st_load_framework.css.scss', File.read("#{dir}/bootstrap3-forms.css.scss") when 'bootstrap4' append_file 'app/assets/stylesheets/1st_load_framework.css.scss', File.read("#{dir}/bootstrap4-forms.css.scss") when 'foundation4' # TODO when 'foundation5' append_file 'app/assets/stylesheets/1st_load_framework.css.scss', File.read("#{dir}/foundation5-forms.css.scss") end end
generate_layout()
click to toggle source
Create an application layout file with partials for messages and navigation
# File lib/generators/layout/install/install_generator.rb, line 93 def generate_layout app = ::Rails.application @app_name = app.class.to_s.split("::").first ext = app.config.generators.options[:rails][:template_engine] || :erb remove_file 'app/views/layouts/application.html.erb' template "#{framework_name}-application.html.#{ext}", "app/views/layouts/application.html.#{ext}" if Rails::VERSION::MAJOR.to_s == "3" gsub_file "app/views/layouts/application.html.#{ext}", /, "data-turbolinks-track" => true/, '' end if framework_name == 'none' remove_file "app/views/layouts/_messages.html.#{ext}" remove_file "app/views/layouts/_navigation.html.#{ext}" remove_file "app/views/layouts/_navigation_links.html.#{ext}" else copy_file "#{framework_name}-messages.html.#{ext}", "app/views/layouts/_messages.html.#{ext}" copy_file "#{framework_name}-navigation.html.#{ext}", "app/views/layouts/_navigation.html.#{ext}" copy_file "navigation_links.html.erb", "app/views/layouts/_navigation_links.html.erb" end end
install_framework()
click to toggle source
Install the desired framework
# File lib/generators/layout/install/install_generator.rb, line 14 def install_framework remove_file 'app/assets/stylesheets/application.css' copy_file 'application.css.scss', 'app/assets/stylesheets/application.css.scss' case framework_name when 'none' copy_file 'application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss' remove_file 'app/assets/stylesheets/foundation_and_overrides.css.scss' remove_file 'app/assets/stylesheets/1st_load_framework.css.scss' when 'simple' copy_file 'simple.css', 'app/assets/stylesheets/simple.css' copy_file 'application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss' remove_file 'app/assets/stylesheets/foundation_and_overrides.css.scss' remove_file 'app/assets/stylesheets/1st_load_framework.css.scss' when 'bootstrap2' copy_file 'bootstrap2_and_overrides.css.scss', 'app/assets/stylesheets/1st_load_framework.css.scss' copy_file 'bootstrap-application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/foundation_and_overrides.css.scss' when 'bootstrap3' copy_file 'bootstrap3_and_overrides.css.scss', 'app/assets/stylesheets/1st_load_framework.css.scss' copy_file 'bootstrap-application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/foundation_and_overrides.css.scss' when 'bootstrap4' copy_file 'bootstrap4_and_overrides.css.scss', 'app/assets/stylesheets/1st_load_framework.css.scss' copy_file 'bootstrap4-application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/foundation_and_overrides.css.scss' when 'foundation4' copy_file 'foundation4_and_overrides.css.scss', 'app/assets/stylesheets/1st_load_framework.css.scss' copy_file 'foundation4-application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss' when 'foundation5' copy_file 'foundation5_and_overrides.css.scss', 'app/assets/stylesheets/1st_load_framework.css.scss' copy_file 'foundation5-application.js', 'app/assets/javascripts/application.js' remove_file 'app/assets/stylesheets/simple.css' remove_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss' insert_into_file('config/application.rb', "\n\n # For Foundation 5\n config.assets.precompile += %w( vendor/modernizr )\n", :after => /^ *# config.i18n.default_locale = :de/, :force => false) end # Rails 3 doesn't have turbolinks # Rails 5.1 uses rails-ujs but earlier versions need jquery_ujs if Rails::VERSION::MAJOR == 3 gsub_file 'app/assets/javascripts/application.js', /\/\/= require turbolinks\n/, '' gsub_file 'app/assets/javascripts/application.js', /\/\/= require rails-ujs/, '//= require jquery_ujs' end if Rails::VERSION::MAJOR == 4 gsub_file 'app/assets/javascripts/application.js', /\/\/= require rails-ujs/, '//= require jquery_ujs' end if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0 gsub_file 'app/assets/javascripts/application.js', /\/\/= require rails-ujs/, '//= require jquery_ujs' end end