Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafamanzo/4deafb6546ffd350a689 to your computer and use it in GitHub Desktop.
Save rafamanzo/4deafb6546ffd350a689 to your computer and use it in GitHub Desktop.
From 6f64ec659606342193256e3b43c1f25687ff0f54 Mon Sep 17 00:00:00 2001
From: Rafael Reggiani Manzo <[email protected]>
Date: Sun, 7 Feb 2016 09:33:44 -0200
Subject: [PATCH] Add compatibility for both sprockets 2 and 3
Compatibility with Rails 4.1 (and so sprockets 2) is still a
requirement. So sprockets 3 specific code have been conditionalized
keeping both versions compatible and thus allowing Rails 5 usage.
---
Gemfile | 2 +-
konacha.gemspec | 2 +-
lib/konacha/engine.rb | 22 ++++++++++++++--------
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/Gemfile b/Gemfile
index 7965f2d..f58a935 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
gemspec
gem "railties", "~> 4.2.0"
-gem "sprockets-rails", ">= 3.0"
+gem "sprockets-rails"
diff --git a/konacha.gemspec b/konacha.gemspec
index 5858084..a84eb86 100644
--- a/konacha.gemspec
+++ b/konacha.gemspec
@@ -22,7 +22,7 @@ the asset pipeline and engines.}
gem.add_dependency "railties", ">= 3.1", "< 5"
gem.add_dependency "actionpack", ">= 3.1", "< 5"
- gem.add_dependency "sprockets", ">= 3", "< 4"
+ gem.add_dependency "sprockets", ">= 2", "< 4"
gem.add_dependency "capybara"
gem.add_dependency "colorize"
gem.add_dependency "tilt"
diff --git a/lib/konacha/engine.rb b/lib/konacha/engine.rb
index 5c6f977..b28a238 100644
--- a/lib/konacha/engine.rb
+++ b/lib/konacha/engine.rb
@@ -7,14 +7,17 @@ module Konacha
config.konacha = ActiveSupport::OrderedOptions.new
def self.application(app)
- app.config.cache_classes = false
- sprockes_env = Sprockets::Railtie.build_environment(app)
+ # Compatibility workaround for supporting both sprockets 2 and 3
+ if Sprockets::VERSION.start_with? '3'
+ app.config.cache_classes = false
+ sprockes_env = Sprockets::Railtie.build_environment(app)
+ end
Rack::Builder.app do
use Rack::ShowExceptions
map app.config.assets.prefix do
- run sprockes_env
+ run Sprockets::VERSION.start_with?('3') ? sprockes_env : app.assets # Compatibility workaround for supporting both sprockets 2 and 3
end
map "/" do
@@ -52,11 +55,14 @@ module Konacha
options.application ||= self.class.application(app)
end
- config.after_initialize do
- ActiveSupport.on_load(:action_view) do
- default_checker = ActionView::Base.precompiled_asset_checker
- ActionView::Base.precompiled_asset_checker = -> logical_path do
- default_checker[logical_path] || Konacha.asset_precompiled?(logical_path)
+ # Compatibility workaround for supporting both sprockets 2 and 3
+ if Sprockets::VERSION.start_with? '3'
+ config.after_initialize do
+ ActiveSupport.on_load(:action_view) do
+ default_checker = ActionView::Base.precompiled_asset_checker
+ ActionView::Base.precompiled_asset_checker = -> logical_path do
+ default_checker[logical_path] || Konacha.asset_precompiled?(logical_path)
+ end
end
end
end
--
2.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment