mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Booya, sprockets now works from Engines.
This commit is contained in:
parent
8e5ff7d0a7
commit
2fe70c1803
7 changed files with 32 additions and 41 deletions
2
Gemfile
2
Gemfile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
env.paths.concat config.assets.paths
|
||||
env.logger = Rails.logger
|
||||
@assets = 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
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def default_asset_path
|
||||
nil
|
||||
end
|
||||
|
@ -239,4 +215,4 @@ module Rails
|
|||
require "rails/console/helpers"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue