Skip to content

Commit

Permalink
Add support for sprockets-rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkravets authored and jfirebaugh committed Feb 8, 2016
1 parent e27938b commit 71b47cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/konacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,20 @@ def spec_paths
}.sort
end
end

def precompiled_assets
%W(konacha.css
chai.js
mocha.js
konacha/parent.js
konacha/iframe.js
konacha/runner.js).concat(spec_paths).map do |path|
path.gsub(/\.js\.coffee$/, ".js").gsub(/\.coffee$/, ".js")
end
end

def asset_precompiled?(logical_path)
precompiled_assets.include? logical_path
end
end
end
23 changes: 20 additions & 3 deletions lib/konacha/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ 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'
app.config.cache_classes = false
sprockets_env = Sprockets::Railtie.build_environment(app)
end

Rack::Builder.app do
use Rack::ShowExceptions

map app.config.assets.prefix do
run app.assets
run Sprockets::VERSION.start_with?('3') ? sprockets_env : app.assets # Compatibility workaround for supporting both sprockets 2 and 3
end

map "/" do
Expand All @@ -37,7 +43,6 @@ def self.formatters
options.spec_matcher ||= /_spec\.|_test\./
options.port ||= 3500
options.host ||= 'localhost'
options.application ||= self.class.application(app)
options.driver ||= :selenium
options.stylesheets ||= %w(application)
options.javascripts ||= %w(chai konacha/iframe)
Expand All @@ -47,7 +52,19 @@ def self.formatters

spec_dirs = [options.spec_dir].flatten
app.config.assets.paths += spec_dirs.map{|d| app.root.join(d).to_s}
app.config.assets.raise_runtime_errors = false
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
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
end
end

0 comments on commit 71b47cc

Please sign in to comment.