Skip to content

Commit 23aca94

Browse files
rafaelfrancaRafael Mendonça França
authored andcommitted
Merge pull request #129 from matthewd/precompile_extensions
Check precompile for the asset's logical_path
1 parent 9aced60 commit 23aca94

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

lib/sprockets/rails/helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def compute_asset_path(path, options = {})
7777
# Computes the full URL to a asset in the public directory. This
7878
# method checks for errors before returning path.
7979
def asset_path(source, options = {})
80-
check_errors_for(source)
80+
check_errors_for(source, options)
8181
path_to_asset(source, options)
8282
end
8383
alias :path_to_asset_with_errors :asset_path
@@ -131,7 +131,7 @@ def javascript_include_tag(*sources)
131131

132132
if options["debug"] != false && request_debug_assets?
133133
sources.map { |source|
134-
check_errors_for(source)
134+
check_errors_for(source, :type => :javascript)
135135
if asset = lookup_asset_for_path(source, :type => :javascript)
136136
asset.to_a.map do |a|
137137
super(path_to_javascript(a.logical_path, :debug => true), options)
@@ -153,7 +153,7 @@ def stylesheet_link_tag(*sources)
153153
options = sources.extract_options!.stringify_keys
154154
if options["debug"] != false && request_debug_assets?
155155
sources.map { |source|
156-
check_errors_for(source)
156+
check_errors_for(source, :type => :stylesheet)
157157
if asset = lookup_asset_for_path(source, :type => :stylesheet)
158158
asset.to_a.map do |a|
159159
super(path_to_stylesheet(a.logical_path, :debug => true), options)
@@ -176,13 +176,13 @@ def check_dependencies!(dep)
176176
end
177177

178178
# Raise errors when source does not exist or is not in the precompiled list
179-
def check_errors_for(source)
179+
def check_errors_for(source, options)
180180
source = source.to_s
181181
return source if !self.raise_runtime_errors || source.blank? || source =~ URI_REGEXP
182-
asset = lookup_asset_for_path(source)
182+
asset = lookup_asset_for_path(source, options)
183183

184-
if asset && asset_needs_precompile?(source, asset.pathname.to_s)
185-
raise AssetFilteredError.new(source)
184+
if asset && asset_needs_precompile?(asset.logical_path, asset.pathname.to_s)
185+
raise AssetFilteredError.new(asset.logical_path)
186186
end
187187
end
188188

test/test_helper.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,34 @@ def test_asset_not_precompiled_error
406406
@view.javascript_include_tag(:foo)
407407
end
408408

409+
Sprockets::Rails::Helper.precompile = ['foo.js']
410+
411+
@view.asset_path("foo.js")
412+
@view.asset_url("foo.js")
413+
@view.javascript_include_tag("foo.js")
414+
@view.javascript_include_tag("foo")
415+
@view.javascript_include_tag(:foo)
416+
417+
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
418+
@view.stylesheet_link_tag("foo")
419+
end
420+
421+
Sprockets::Rails::Helper.precompile = ['foo.css']
422+
409423
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
410-
@view.stylesheet_link_tag("foo.js")
424+
@view.javascript_include_tag("foo")
411425
end
412426

427+
@view.stylesheet_link_tag("foo")
428+
413429
Sprockets::Rails::Helper.precompile = [ lambda {|logical_path| true } ]
414430

415431
@view.asset_path("foo.js")
416432
@view.asset_url("foo.js")
417433
@view.javascript_include_tag("foo.js")
418434
@view.javascript_include_tag("foo")
419435
@view.javascript_include_tag(:foo)
420-
@view.stylesheet_link_tag("foo.js")
436+
@view.stylesheet_link_tag("foo")
421437
end
422438

423439
def test_asset_digest_path
@@ -434,8 +450,6 @@ def test_asset_digest
434450
class AutomaticDependenciesFromHelpersTest < HelperTest
435451

436452
def test_dependency_added
437-
@view.assets_environment = @assets
438-
439453
@view.asset_path("url.css")
440454

441455
assert_equal ["logo.png", "url.css.erb"], @assets['url.css'].send(:dependency_paths).map {|d| File.basename(d.pathname) }.sort

0 commit comments

Comments
 (0)