mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix the lame config.action_controller.present? check scattered throughout assets_path.
Conflicts: actionpack/test/template/sprockets_helper_test.rb
This commit is contained in:
parent
ee2be435b1
commit
87c57bb88f
7 changed files with 32 additions and 30 deletions
|
@ -86,9 +86,7 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_protocol
|
def default_protocol
|
||||||
protocol = @config.action_controller.default_asset_host_protocol if @config.action_controller.present?
|
@config.default_asset_host_protocol || (has_request? ? :request : :relative)
|
||||||
protocol ||= @config.default_asset_host_protocol
|
|
||||||
protocol || (has_request? ? :request : :relative)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def invalid_asset_host!(help_message)
|
def invalid_asset_host!(help_message)
|
||||||
|
@ -117,19 +115,11 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_url_root
|
def relative_url_root
|
||||||
if config.action_controller.present?
|
config.relative_url_root
|
||||||
config.action_controller.relative_url_root
|
|
||||||
else
|
|
||||||
config.relative_url_root
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_host_config
|
def asset_host_config
|
||||||
if config.action_controller.present?
|
config.asset_host
|
||||||
config.action_controller.asset_host
|
|
||||||
else
|
|
||||||
config.asset_host
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the current request if one exists.
|
# Returns the current request if one exists.
|
||||||
|
|
|
@ -39,12 +39,13 @@ namespace :assets do
|
||||||
config = Rails.application.config
|
config = Rails.application.config
|
||||||
config.assets.compile = true
|
config.assets.compile = true
|
||||||
config.assets.digest = digest unless digest.nil?
|
config.assets.digest = digest unless digest.nil?
|
||||||
|
|
||||||
config.assets.digests = {}
|
config.assets.digests = {}
|
||||||
|
|
||||||
env = Rails.application.assets
|
env = Rails.application.assets
|
||||||
|
env.context_class.send :include, ::Sprockets::Helpers::PrecompileHelper
|
||||||
|
|
||||||
target = File.join(Rails.public_path, config.assets.prefix)
|
target = File.join(Rails.public_path, config.assets.prefix)
|
||||||
compiler = Sprockets::StaticCompiler.new(env,
|
compiler = Sprockets::StaticCompiler.new(env,
|
||||||
target,
|
target,
|
||||||
config.assets.precompile,
|
config.assets.precompile,
|
||||||
:manifest_path => config.assets.manifest,
|
:manifest_path => config.assets.manifest,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Sprockets
|
module Sprockets
|
||||||
module Helpers
|
module Helpers
|
||||||
autoload :RailsHelper, "sprockets/helpers/rails_helper"
|
autoload :RailsHelper, "sprockets/helpers/rails_helper"
|
||||||
|
autoload :PrecompileHelper, "sprockets/helpers/precompile_helper"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
13
actionpack/lib/sprockets/helpers/precompile_helper.rb
Normal file
13
actionpack/lib/sprockets/helpers/precompile_helper.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module Sprockets
|
||||||
|
module Helpers
|
||||||
|
module PrecompileHelper
|
||||||
|
def controller
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def config
|
||||||
|
Rails.application.config.action_controller
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -8,9 +8,6 @@ module Sprockets
|
||||||
|
|
||||||
def asset_paths
|
def asset_paths
|
||||||
@asset_paths ||= begin
|
@asset_paths ||= begin
|
||||||
config = self.config if respond_to?(:config)
|
|
||||||
config ||= Rails.application.config
|
|
||||||
controller = self.controller if respond_to?(:controller)
|
|
||||||
paths = RailsHelper::AssetPaths.new(config, controller)
|
paths = RailsHelper::AssetPaths.new(config, controller)
|
||||||
paths.asset_environment = asset_environment
|
paths.asset_environment = asset_environment
|
||||||
paths.asset_digests = asset_digests
|
paths.asset_digests = asset_digests
|
||||||
|
|
|
@ -43,10 +43,7 @@ module Sprockets
|
||||||
|
|
||||||
ActiveSupport.on_load(:action_view) do
|
ActiveSupport.on_load(:action_view) do
|
||||||
include ::Sprockets::Helpers::RailsHelper
|
include ::Sprockets::Helpers::RailsHelper
|
||||||
|
app.assets.context_class.send :include, ::Sprockets::Helpers::RailsHelper
|
||||||
app.assets.context_class.instance_eval do
|
|
||||||
include ::Sprockets::Helpers::RailsHelper
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
application = Struct.new(:config, :assets).new(config, @assets)
|
application = Struct.new(:config, :assets).new(config, @assets)
|
||||||
Rails.stubs(:application).returns(application)
|
Rails.stubs(:application).returns(application)
|
||||||
@config = config
|
@config = config
|
||||||
@config.action_controller ||= ActiveSupport::InheritableOptions.new
|
|
||||||
@config.perform_caching = true
|
@config.perform_caching = true
|
||||||
@config.assets.digest = true
|
@config.assets.digest = true
|
||||||
@config.assets.compile = true
|
@config.assets.compile = true
|
||||||
|
@ -38,6 +37,10 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
"http://www.example.com"
|
"http://www.example.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def config
|
||||||
|
@controller ? @controller.config : @config
|
||||||
|
end
|
||||||
|
|
||||||
test "asset_path" do
|
test "asset_path" do
|
||||||
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
||||||
asset_path("logo.png")
|
asset_path("logo.png")
|
||||||
|
@ -116,7 +119,7 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
test "stylesheets served without a controller in scope cannot access the request" do
|
test "stylesheets served without a controller in scope cannot access the request" do
|
||||||
@controller = nil
|
@controller = nil
|
||||||
@config.action_controller.asset_host = Proc.new do |asset, request|
|
@config.asset_host = Proc.new do |asset, request|
|
||||||
fail "This should not have been called."
|
fail "This should not have been called."
|
||||||
end
|
end
|
||||||
assert_raises ActionController::RoutingError do
|
assert_raises ActionController::RoutingError do
|
||||||
|
@ -154,9 +157,9 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
|
test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
|
||||||
@controller = nil
|
@controller = nil
|
||||||
@config.action_controller.asset_host = "assets-%d.example.com"
|
@config.asset_host = "assets-%d.example.com"
|
||||||
@config.action_controller.default_asset_host_protocol = :request
|
@config.default_asset_host_protocol = :request
|
||||||
@config.action_controller.perform_caching = true
|
@config.perform_caching = true
|
||||||
|
|
||||||
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
||||||
asset_path("logo.png")
|
asset_path("logo.png")
|
||||||
|
@ -170,7 +173,7 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
test "asset path with relative url root when controller isn't present but relative_url_root is" do
|
test "asset path with relative url root when controller isn't present but relative_url_root is" do
|
||||||
@controller = nil
|
@controller = nil
|
||||||
@config.action_controller.relative_url_root = "/collaboration/hieraki"
|
@config.relative_url_root = "/collaboration/hieraki"
|
||||||
assert_equal "/collaboration/hieraki/images/logo.gif",
|
assert_equal "/collaboration/hieraki/images/logo.gif",
|
||||||
asset_path("/images/logo.gif")
|
asset_path("/images/logo.gif")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue