Skip to content

Allow users to skip asset dependency checks #100

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

Merged
Merged
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/m

Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.

**`config.assets.raise_runtime_errors`**

Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`.

**`config.assets.paths`**

Add additional load paths to this Array. Rails includes `app/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to to this.
Expand Down
7 changes: 6 additions & 1 deletion lib/sprockets/rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
module Sprockets
module Rails
module Helper
# support for Ruby 1.9.3 && Rails 3.0.x
@_config = ActiveSupport::InheritableOptions.new({}) unless defined?(ActiveSupport::Configurable::Configuration)
include ActiveSupport::Configurable
config_accessor :raise_runtime_errors

class DependencyError < StandardError
def initialize(path, dep)
msg = "Asset depends on '#{dep}' to generate properly but has not declared the dependency\n"
Expand Down Expand Up @@ -139,7 +144,7 @@ def stylesheet_link_tag(*sources)

# Checks if the asset is included in the dependencies list.
def check_dependencies!(dep)
if !_dependency_assets.detect { |asset| asset.include?(dep) }
if raise_runtime_errors && !_dependency_assets.detect { |asset| asset.include?(dep) }
raise DependencyError.new(self.pathname, dep)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def configure(&block)
app.assets = app.assets.index
end

Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors

if config.assets.compile
if app.routes.respond_to?(:prepend)
app.routes.prepend do
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,12 @@ def test_asset_digest

class ErrorsInHelpersTest < HelperTest
def test_dependency_error
@view.raise_runtime_errors = true
assert_raise Sprockets::Rails::Helper::DependencyError do
@assets['error/dependency.js'].to_s
end

@view.raise_runtime_errors = false
@assets['error/dependency.js'].to_s
end
end