diff options
author | José Valim <jose.valim@gmail.com> | 2011-04-15 18:42:51 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-15 18:43:22 +0200 |
commit | 2fe70c180351e87801179e8404d1582d7da25645 (patch) | |
tree | 26c5cd071089cd94195a98cdc7ad8cb7fa8236e8 | |
parent | 8e5ff7d0a7479e72764763af027973f82c49618c (diff) | |
download | rails-2fe70c180351e87801179e8404d1582d7da25645.tar.gz rails-2fe70c180351e87801179e8404d1582d7da25645.tar.bz2 rails-2fe70c180351e87801179e8404d1582d7da25645.zip |
Booya, sprockets now works from Engines.
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 40 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/engine/configuration.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 5 | ||||
-rw-r--r-- | railties/test/railties/shared_tests.rb | 12 |
7 files changed, 32 insertions, 41 deletions
@@ -12,6 +12,7 @@ gem "rack", :git => "git://github.com/rack/rack.git" gem "rack-test", :git => "git://github.com/brynary/rack-test.git" gem "sprockets", :git => "git://github.com/sstephenson/sprockets.git" +gem "coffee-script" gem "rake", ">= 0.8.7" gem "mocha", ">= 0.9.8" @@ -30,6 +31,7 @@ platforms :mri_18 do gem "system_timer" gem "ruby-debug", ">= 0.10.3" gem 'ruby-prof' + gem "json" end platforms :mri_19 do diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index e3942f0f1f..580f29b767 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -50,6 +50,7 @@ module Rails end end + attr_accessor :assets delegate :default_url_options, :default_url_options=, :to => :routes # This method is called just after an application inherits from Rails::Application, @@ -116,8 +117,6 @@ module Rails self end - alias :build_middleware_stack :app - def env_config @env_config ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, @@ -137,42 +136,19 @@ module Rails @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd)) end - def assets - @assets ||= build_asset_environment - end - attr_writer :assets + protected + + alias :build_middleware_stack :app def build_asset_environment - return unless config.assets.enabled require 'sprockets' env = Sprockets::Environment.new(root.to_s) env.static_root = File.join(root.join("public"), config.assets.prefix) - env - end - - initializer :add_sprockets_paths do |app| - if config.assets.enabled - paths = [ - "app/assets/javascripts", - "app/assets/stylesheets", - "vendor/assets/javascripts", - "vendor/assets/stylesheets", - "vendor/plugins/*/app/javascripts", - "vendor/plugins/*/app/stylesheets", - "vendor/plugins/*/javascripts", - "vendor/plugins/*/stylesheets" - ] + config.assets.paths - - paths.each do |pattern| - Dir[app.root.join(pattern)].each do |dir| - app.assets.paths << dir - end - end - end + env.paths.concat config.assets.paths + env.logger = Rails.logger + @assets = env end - protected - def default_asset_path nil end @@ -239,4 +215,4 @@ module Rails require "rails/console/helpers" end end -end +end
\ No newline at end of file diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index bae464a840..838e50de6c 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -36,18 +36,13 @@ module Rails initializer :add_sprockets_route do |app| assets = config.assets if assets.enabled + build_asset_environment app.routes.append do mount app.assets => assets.prefix end end end - initializer :set_sprockets_logger do |app| - if config.assets.enabled - app.assets.logger = Rails.logger - end - end - initializer :index_sprockets_environment do |app| if config.assets.enabled && config.action_controller.perform_caching app.assets = app.assets.index diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index ee265366ff..e201aa591d 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -518,6 +518,11 @@ module Rails end end + initializer :append_app_assets_path do |app| + app.config.assets.paths.unshift *paths["vendor/assets"].existent + app.config.assets.paths.unshift *paths["app/assets"].existent + end + initializer :prepend_helpers_path do |app| if !isolated? || (app == self) app.config.helpers_paths.unshift(*paths["app/helpers"].existent) diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 4f458b0aee..83f12d137b 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -40,6 +40,7 @@ module Rails @paths ||= begin paths = Rails::Paths::Root.new(@root) paths.add "app", :eager_load => true, :glob => "*" + paths.add "app/assets", :glob => "*" paths.add "app/controllers", :eager_load => true paths.add "app/helpers", :eager_load => true paths.add "app/models", :eager_load => true @@ -59,6 +60,7 @@ module Rails paths.add "public/javascripts" paths.add "public/stylesheets" paths.add "vendor", :load_path => true + paths.add "vendor/assets", :glob => "*" paths.add "vendor/plugins" paths end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 20797a2b0c..f7423cd566 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1,8 +1,7 @@ require "isolation/abstract_unit" require "railties/shared_tests" -require 'stringio' -require 'rack/test' -require 'rack/file' +require "stringio" +require "rack/test" module RailtiesTest class EngineTest < Test::Unit::TestCase diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 3eb79d57c8..5cd1818f4b 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -48,6 +48,18 @@ module RailtiesTest end end + def test_serving_sprockets_assets + @plugin.write "app/assets/javascripts/engine.js.coffee", "square = (x) -> x * x" + + boot_rails + require 'rack/test' + require 'coffee_script' + extend Rack::Test::Methods + + get "/assets/engine.js" + assert_match "square = function(x) {", last_response.body + end + def test_copying_migrations @plugin.write "db/migrate/1_create_users.rb", <<-RUBY class CreateUsers < ActiveRecord::Migration |