Class: Layout::Generators::LayoutGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Layout::Generators::LayoutGenerator
- Defined in:
- lib/generators/layout/layout_generator.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
Instance Method Summary collapse
-
#add_navigation_links ⇒ Object
If ‘About’ or ‘Contact’ views exist in known locations, add navigation links.
-
#generate_layout ⇒ Object
Create an application layout file with partials for messages and navigation.
-
#install_framework ⇒ Object
Install the desired framework.
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/generators/layout/layout_generator.rb', line 9 def app_name @app_name end |
Instance Method Details
#add_navigation_links ⇒ Object
If ‘About’ or ‘Contact’ views exist in known locations, add navigation links
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/layout/layout_generator.rb', line 66 def unless framework_name == 'none' # not yet accommodating Slim (we'll need different substitutions) if File.exists?('app/views/pages/about.html.erb') insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'About', page_path('about') %></li>", :before => "\n</ul>" end if File.exists?('app/views/contacts/new.html.erb') insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'Contact', new_contact_path %></li>", :before => "\n</ul>" end if File.exists?('app/views/contacts/new.html.haml') insert_into_file 'app/views/layouts/_navigation.html.haml', "\n %li= link_to 'Contact', new_contact_path", :after => "root_path" end if File.exists?('app/views/pages/about.html.haml') insert_into_file 'app/views/layouts/_navigation.html.haml', "\n %li= link_to 'About', page_path('about')", :after => "root_path" end end end |
#generate_layout ⇒ Object
Create an application layout file with partials for messages and navigation
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/layout/layout_generator.rb', line 48 def generate_layout app = ::Rails.application @app_name = app.class.to_s.split("::").first ext = app.config.generators.[:rails][:template_engine] || :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}" 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}" end end |
#install_framework ⇒ Object
Install the desired framework
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/layout/layout_generator.rb', line 12 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' 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' when 'bootstrap2' copy_file 'bootstrap2_and_overrides.css.scss', 'app/assets/stylesheets/bootstrap_and_overrides.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/bootstrap_and_overrides.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 'foundation4' copy_file 'foundation_and_overrides.css.scss', 'app/assets/stylesheets/foundation_and_overrides.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' end if Rails::VERSION::MAJOR.to_s == "3" gsub_file 'app/assets/javascripts/application.js', /\/\/= require turbolinks\n/, '' end end |