Skip to content

Commit 1d889e9

Browse files
committed
Allow users to skip asset dependency checks
1 parent 17264b3 commit 1d889e9

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/m
5555

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

58+
**`config.assets.raise_runtime_errors`**
59+
60+
Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`.
61+
5862
**`config.assets.paths`**
5963

6064
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.

lib/sprockets/rails/helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
module Sprockets
66
module Rails
77
module Helper
8+
# support for Ruby 1.9.3 && Rails 3.0.x
9+
@_config = ActiveSupport::InheritableOptions.new({}) unless defined?(ActiveSupport::Configurable::Configuration)
10+
include ActiveSupport::Configurable
11+
config_accessor :raise_runtime_errors
12+
813
class DependencyError < StandardError
914
def initialize(path, dep)
1015
msg = "Asset depends on '#{dep}' to generate properly but has not declared the dependency\n"
@@ -139,7 +144,7 @@ def stylesheet_link_tag(*sources)
139144

140145
# Checks if the asset is included in the dependencies list.
141146
def check_dependencies!(dep)
142-
if !_dependency_assets.detect { |asset| asset.include?(dep) }
147+
if raise_runtime_errors && !_dependency_assets.detect { |asset| asset.include?(dep) }
143148
raise DependencyError.new(self.pathname, dep)
144149
end
145150
end

lib/sprockets/railtie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def configure(&block)
113113
app.assets = app.assets.index
114114
end
115115

116+
Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors
117+
116118
if config.assets.compile
117119
if app.routes.respond_to?(:prepend)
118120
app.routes.prepend do

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,12 @@ def test_asset_digest
385385

386386
class ErrorsInHelpersTest < HelperTest
387387
def test_dependency_error
388+
@view.raise_runtime_errors = true
388389
assert_raise Sprockets::Rails::Helper::DependencyError do
389390
@assets['error/dependency.js'].to_s
390391
end
392+
393+
@view.raise_runtime_errors = false
394+
@assets['error/dependency.js'].to_s
391395
end
392396
end

0 commit comments

Comments
 (0)