Skip to content

Commit 85b89c4

Browse files
committed
Merge pull request #238 from arthurnn/fix_route_wrapper_internal
Move assets route internal decoration.
2 parents 1548551 + f355879 commit 85b89c4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/sprockets/rails/route_wrapper.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Sprockets
2+
module Rails
3+
module RouteWrapper
4+
5+
def internal_assets_path?
6+
path =~ %r{\A#{self.class.assets_prefix}\z}
7+
end
8+
9+
def internal?
10+
super || internal_assets_path?
11+
end
12+
13+
def self.included(klass)
14+
klass.class_eval do
15+
def internal_with_sprockets?
16+
internal_without_sprockets? || internal_assets_path?
17+
end
18+
alias_method_chain :internal?, :sprockets
19+
end
20+
end
21+
end
22+
end
23+
end

lib/sprockets/railtie.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'sprockets'
77
require 'sprockets/rails/context'
88
require 'sprockets/rails/helper'
9+
require 'sprockets/rails/route_wrapper'
910
require 'sprockets/rails/version'
1011

1112
module Rails
@@ -146,6 +147,18 @@ def self.build_manifest(app)
146147
end
147148
app.assets_manifest = build_manifest(app)
148149

150+
ActionDispatch::Routing::RouteWrapper.class_eval do
151+
class_attribute :assets_prefix
152+
153+
if defined?(prepend) && ::Rails.version >= '4'
154+
prepend Sprockets::Rails::RouteWrapper
155+
else
156+
include Sprockets::Rails::RouteWrapper
157+
end
158+
159+
self.assets_prefix = config.assets.prefix
160+
end
161+
149162
ActiveSupport.on_load(:action_view) do
150163
include Sprockets::Rails::Helper
151164

0 commit comments

Comments
 (0)