Skip to content

Commit

Permalink
Adding backwards compatibility with sprockets 3 and sprocket-rails 2
Browse files Browse the repository at this point in the history
This should make @alexkravets work fix the issues pointed by @jfirebaugh
in #219.
Simply specify conditionals around sprocket-rails 3 (instead of
sprockets 3) since the breaking changes come from sprocket-rails.
Also, early versions of sprocket-rails 2 didn't have VERSION and didn't
require it properly
(rails/sprockets-rails#131).
  • Loading branch information
Hugo Corbucci authored and jfirebaugh committed Feb 11, 2016
1 parent 71b47cc commit 857dd37
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/konacha/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Engine < ::Rails::Engine
config.konacha = ActiveSupport::OrderedOptions.new

def self.application(app)
# Compatibility workaround for supporting both sprockets 2 and 3
if Sprockets::VERSION.start_with? '3'
# Compatibility workaround for supporting both sprockets 2 and 3 with sprocket-rails 2 or 3
if defined?(Sprockets::Rails::VERSION) && Sprockets::Rails::VERSION.start_with?('3')
app.config.cache_classes = false
sprockets_env = Sprockets::Railtie.build_environment(app)
end
Expand All @@ -17,7 +17,12 @@ def self.application(app)
use Rack::ShowExceptions

map app.config.assets.prefix do
run Sprockets::VERSION.start_with?('3') ? sprockets_env : app.assets # Compatibility workaround for supporting both sprockets 2 and 3
# Compatibility workaround for supporting both sprockets 2 and 3 with sprocket-rails 2 or 3
if defined?(Sprockets::Rails::VERSION) && Sprockets::Rails::VERSION.start_with?('3')
run sprockets_env
else
run app.assets
end
end

map "/" do
Expand Down Expand Up @@ -52,12 +57,15 @@ def self.formatters

spec_dirs = [options.spec_dir].flatten
app.config.assets.paths += spec_dirs.map{|d| app.root.join(d).to_s}
if !defined?(Sprockets::Rails::VERSION) || Sprockets::Rails::VERSION.start_with?('2')
app.config.assets.raise_runtime_errors = false
end
options.application ||= self.class.application(app)
end

# Compatibility workaround for supporting both sprockets 2 and 3
if Sprockets::VERSION.start_with? '3'
config.after_initialize do
config.after_initialize do
# Compatibility workaround for supporting both sprockets 2 and 3 with sprocket-rails 2 or 3
if defined?(Sprockets::Rails::VERSION) && Sprockets::Rails::VERSION.start_with?('3')
ActiveSupport.on_load(:action_view) do
default_checker = ActionView::Base.precompiled_asset_checker
ActionView::Base.precompiled_asset_checker = -> logical_path do
Expand Down

0 comments on commit 857dd37

Please sign in to comment.