Skip to content

Commit f355879

Browse files
committed
Use prepend when available
1 parent cf86cf7 commit f355879

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/sprockets/rails/route_wrapper.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
module Sprockets
22
module Rails
33
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+
413
def self.included(klass)
5-
klass.class_attribute(:assets_prefix)
614
klass.class_eval do
7-
def assets_prefix
8-
self.class.assets_prefix
9-
end
10-
1115
def internal_with_sprockets?
12-
internal_without_sprockets? || path =~ %r{\A#{assets_prefix}\z}
16+
internal_without_sprockets? || internal_assets_path?
1317
end
1418
alias_method_chain :internal?, :sprockets
1519
end

lib/sprockets/railtie.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ def self.build_manifest(app)
148148
app.assets_manifest = build_manifest(app)
149149

150150
ActionDispatch::Routing::RouteWrapper.class_eval do
151-
include Sprockets::Rails::RouteWrapper
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
152158

153159
self.assets_prefix = config.assets.prefix
154160
end

0 commit comments

Comments
 (0)