Skip to content
This repository
Browse code

Merge pull request #1672 from ryanb/namespace_engine_assets

Namespace engine assets
  • Loading branch information...
commit c41c4425eef7eef01d80fa6007e64d9830b8837d 2 parents 86bbba1 + 4dc3bb9
José Valim josevalim authored
14 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -11,15 +11,15 @@ def rakefile
11 11 def app
12 12 if mountable?
13 13 directory "app"
14   - template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
  14 + template "app/views/layouts/application.html.erb.tt",
15 15 "app/views/layouts/#{name}/application.html.erb"
16   - empty_directory_with_gitkeep "app/assets/images"
  16 + empty_directory_with_gitkeep "app/assets/images/#{name}"
17 17 elsif full?
18 18 empty_directory_with_gitkeep "app/models"
19 19 empty_directory_with_gitkeep "app/controllers"
20 20 empty_directory_with_gitkeep "app/views"
21 21 empty_directory_with_gitkeep "app/helpers"
22   - empty_directory_with_gitkeep "app/assets/images"
  22 + empty_directory_with_gitkeep "app/assets/images/#{name}"
23 23 end
24 24 end
25 25
@@ -108,9 +108,9 @@ def test_dummy_clean
108 108 def stylesheets
109 109 if mountable?
110 110 copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
111   - "app/assets/stylesheets/application.css"
  111 + "app/assets/stylesheets/#{name}/application.css"
112 112 elsif full?
113   - empty_directory_with_gitkeep "app/assets/stylesheets"
  113 + empty_directory_with_gitkeep "app/assets/stylesheets/#{name}"
114 114 end
115 115 end
116 116
@@ -119,9 +119,9 @@ def javascripts
119 119
120 120 if mountable?
121 121 template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
122   - "app/assets/javascripts/application.js"
  122 + "app/assets/javascripts/#{name}/application.js"
123 123 elsif full?
124   - empty_directory_with_gitkeep "app/assets/javascripts"
  124 + empty_directory_with_gitkeep "app/assets/javascripts/#{name}"
125 125 end
126 126 end
127 127
14 railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt
... ... @@ -0,0 +1,14 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title><%= camelized %></title>
  5 + <%%= stylesheet_link_tag "<%= name %>/application" %>
  6 + <%%= javascript_include_tag "<%= name %>/application" %>
  7 + <%%= csrf_meta_tags %>
  8 +</head>
  9 +<body>
  10 +
  11 +<%%= yield %>
  12 +
  13 +</body>
  14 +</html>
28 railties/test/generators/plugin_new_generator_test.rb
@@ -101,19 +101,19 @@ def test_generation_runs_bundle_install_with_full_and_mountable
101 101
102 102 def test_skipping_javascripts_without_mountable_option
103 103 run_generator
104   - assert_no_file "app/assets/javascripts/application.js"
  104 + assert_no_file "app/assets/javascripts/bukkits/application.js"
105 105 assert_no_file "vendor/assets/javascripts/jquery.js"
106 106 assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
107 107 end
108 108
109 109 def test_javascripts_generation
110 110 run_generator [destination_root, "--mountable"]
111   - assert_file "app/assets/javascripts/application.js"
  111 + assert_file "app/assets/javascripts/bukkits/application.js"
112 112 end
113 113
114 114 def test_jquery_is_the_default_javascript_library
115 115 run_generator [destination_root, "--mountable"]
116   - assert_file "app/assets/javascripts/application.js" do |contents|
  116 + assert_file "app/assets/javascripts/bukkits/application.js" do |contents|
117 117 assert_match %r{^//= require jquery}, contents
118 118 assert_match %r{^//= require jquery_ujs}, contents
119 119 end
@@ -124,7 +124,7 @@ def test_jquery_is_the_default_javascript_library
124 124
125 125 def test_other_javascript_libraries
126 126 run_generator [destination_root, "--mountable", '-j', 'prototype']
127   - assert_file "app/assets/javascripts/application.js" do |contents|
  127 + assert_file "app/assets/javascripts/bukkits/application.js" do |contents|
128 128 assert_match %r{^//= require prototype}, contents
129 129 assert_match %r{^//= require prototype_ujs}, contents
130 130 end
@@ -135,7 +135,7 @@ def test_other_javascript_libraries
135 135
136 136 def test_skip_javascripts
137 137 run_generator [destination_root, "--skip-javascript", "--mountable"]
138   - assert_no_file "app/assets/javascripts/application.js"
  138 + assert_no_file "app/assets/javascripts/bukkits/application.js"
139 139 assert_no_file "vendor/assets/javascripts/jquery.js"
140 140 assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
141 141 end
@@ -161,9 +161,9 @@ def test_ensure_that_tests_works_in_full_mode
161 161
162 162 def test_creating_engine_in_full_mode
163 163 run_generator [destination_root, "--full"]
164   - assert_file "app/assets/javascripts"
165   - assert_file "app/assets/stylesheets"
166   - assert_file "app/assets/images"
  164 + assert_file "app/assets/javascripts/bukkits"
  165 + assert_file "app/assets/stylesheets/bukkits"
  166 + assert_file "app/assets/images/bukkits"
167 167 assert_file "app/models"
168 168 assert_file "app/controllers"
169 169 assert_file "app/views"
@@ -180,15 +180,19 @@ def test_being_quiet_while_creating_dummy_application
180 180
181 181 def test_create_mountable_application_with_mountable_option
182 182 run_generator [destination_root, "--mountable"]
183   - assert_file "app/assets/javascripts"
184   - assert_file "app/assets/stylesheets"
185   - assert_file "app/assets/images"
  183 + assert_file "app/assets/javascripts/bukkits"
  184 + assert_file "app/assets/stylesheets/bukkits"
  185 + assert_file "app/assets/images/bukkits"
186 186 assert_file "config/routes.rb", /Bukkits::Engine.routes.draw do/
187 187 assert_file "lib/bukkits/engine.rb", /isolate_namespace Bukkits/
188 188 assert_file "test/dummy/config/routes.rb", /mount Bukkits::Engine => "\/bukkits"/
189 189 assert_file "app/controllers/bukkits/application_controller.rb", /module Bukkits\n class ApplicationController < ActionController::Base/
190 190 assert_file "app/helpers/bukkits/application_helper.rb", /module Bukkits\n module ApplicationHelper/
191   - assert_file "app/views/layouts/bukkits/application.html.erb", /<title>Bukkits<\/title>/
  191 + assert_file "app/views/layouts/bukkits/application.html.erb" do |contents|
  192 + assert_match "<title>Bukkits</title>", contents
  193 + assert_match /stylesheet_link_tag\s+['"]bukkits\/application['"]/, contents
  194 + assert_match /javascript_include_tag\s+['"]bukkits\/application['"]/, contents
  195 + end
192 196 end
193 197
194 198 def test_creating_gemspec

0 comments on commit c41c442

Please sign in to comment.
Something went wrong with that request. Please try again.