Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Sprockets 3.0 #217

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'
gemspec

gem "railties", "~> 4.2.0"
gem "sprockets-rails"
gem "sprockets-rails", ">= 3.0"
4 changes: 2 additions & 2 deletions konacha.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ the asset pipeline and engines.}
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "konacha"
gem.require_paths = ["lib"]
gem.version = "3.7.0"
gem.version = "3.8.0"
gem.license = "MIT"

gem.add_dependency "railties", ">= 3.1", "< 5"
gem.add_dependency "actionpack", ">= 3.1", "< 5"
gem.add_dependency "sprockets", ">= 2", "< 4"
gem.add_dependency "sprockets", ">= 3", "< 4"
gem.add_dependency "capybara"
gem.add_dependency "colorize"
gem.add_dependency "tilt"
Expand Down
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
17 changes: 14 additions & 3 deletions lib/konacha/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ class Engine < ::Rails::Engine
config.konacha = ActiveSupport::OrderedOptions.new

def self.application(app)
app.config.cache_classes = false
sprockes_env = Sprockets::Railtie.build_environment(app)

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

map app.config.assets.prefix do
run app.assets
run sprockes_env
end

map "/" do
Expand All @@ -37,7 +40,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 +49,16 @@ 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

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