Skip to content

Commit

Permalink
Remove dependency on actionpack in ActionView::AssetPaths
Browse files Browse the repository at this point in the history
Since Action View should not depend on actionpack, it's best to delegate
invalid_asset_host! to controller and just rely on such simple contract
instead of raising ActionController::RoutingError directly.
  • Loading branch information
drogus committed Aug 28, 2012
1 parent 1ec1eb2 commit 7185e35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_controller.rb
Expand Up @@ -12,6 +12,7 @@ module ActionController
autoload :Middleware autoload :Middleware


autoload_under "metal" do autoload_under "metal" do
autoload :AssetPaths
autoload :Compatibility autoload :Compatibility
autoload :ConditionalGet autoload :ConditionalGet
autoload :Cookies autoload :Cookies
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/base.rb
Expand Up @@ -183,8 +183,8 @@ def self.without_modules(*modules)
MODULES = [ MODULES = [
AbstractController::Layouts, AbstractController::Layouts,
AbstractController::Translation, AbstractController::Translation,
AbstractController::AssetPaths,


AssetPaths,
Helpers, Helpers,
HideActions, HideActions,
UrlFor, UrlFor,
Expand Down
15 changes: 15 additions & 0 deletions actionpack/lib/action_controller/metal/asset_paths.rb
@@ -0,0 +1,15 @@
require 'action_controller/metal/exceptions'

module ActionController
module AssetPaths
extend ActiveSupport::Concern

included do
include AbstractController::AssetPaths
end

def invalid_asset_host!(help_message)
raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
end
end
end
8 changes: 3 additions & 5 deletions actionpack/lib/action_view/asset_paths.rb
@@ -1,13 +1,15 @@
require 'zlib' require 'zlib'
require 'active_support/core_ext/file' require 'active_support/core_ext/file'
require 'action_controller/metal/exceptions' require 'active_support/core_ext/module/delegation'


module ActionView module ActionView
class AssetPaths #:nodoc: class AssetPaths #:nodoc:
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//} URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}


attr_reader :config, :controller attr_reader :config, :controller


delegate :invalid_asset_host!, :to => :controller, :prefix => false

def initialize(config, controller = nil) def initialize(config, controller = nil)
@config = config @config = config
@controller = controller @controller = controller
Expand Down Expand Up @@ -97,10 +99,6 @@ def default_protocol
@config.default_asset_host_protocol || (has_request? ? :request : :relative) @config.default_asset_host_protocol || (has_request? ? :request : :relative)
end end


def invalid_asset_host!(help_message)
raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
end

# Pick an asset host for this source. Returns +nil+ if no host is set, # Pick an asset host for this source. Returns +nil+ if no host is set,
# the host if no wildcard is set, the host interpolated with the # the host if no wildcard is set, the host interpolated with the
# numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4), # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
Expand Down

0 comments on commit 7185e35

Please sign in to comment.