Skip to content
This repository
Browse code

Merge pull request #2876 from alex3/patch-1

Fixed assets precompile regex
  • Loading branch information...
commit 082f53a3bca9dce70adcf41094e246d2c9fed934 1 parent 562277b
Santiago Pastorino spastorino authored
2  actionpack/lib/sprockets/assets.rake
@@ -26,6 +26,8 @@ namespace :assets do
26 26 env.each_logical_path do |logical_path|
27 27 if path.is_a?(Regexp)
28 28 next unless path.match(logical_path)
  29 + elsif path.is_a?(Proc)
  30 + next unless path.call(logical_path)
29 31 else
30 32 next unless File.fnmatch(path.to_s, logical_path)
31 33 end
3  railties/lib/rails/application/configuration.rb
@@ -37,7 +37,8 @@ def initialize(*)
37 37 @assets = ActiveSupport::OrderedOptions.new
38 38 @assets.enabled = false
39 39 @assets.paths = []
40   - @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
  40 + @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) },
  41 + /application.(css|js)$/ ]
41 42 @assets.prefix = "/assets"
42 43 @assets.version = ''
43 44 @assets.debug = false
28 railties/test/application/assets_test.rb
@@ -64,6 +64,34 @@ def app
64 64 end
65 65 end
66 66
  67 + test "precompile application.js and application.css and all other files not ending with .js or .css by default" do
  68 + app_file "app/assets/javascripts/application.js", "alert();"
  69 + app_file "app/assets/stylesheets/application.css", "body{}"
  70 + app_file "app/assets/javascripts/something.min.js", "alert();"
  71 + app_file "app/assets/stylesheets/something.min.css", "body{}"
  72 +
  73 + images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png",
  74 + "happy-face.png", "happy.happy_face.png", "happy_happy.face.png",
  75 + "happy.happy.face.png", "happy", "happy.face", "-happyface",
  76 + "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png",
  77 + "_happy.png"]
  78 + images_should_compile.each do |filename|
  79 + app_file "app/assets/images/#{filename}", "happy"
  80 + end
  81 +
  82 + capture(:stdout) do
  83 + Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
  84 + end
  85 +
  86 + images_should_compile.each do |filename|
  87 + assert File.exists?("#{app_path}/public/assets/#{filename}")
  88 + end
  89 + assert File.exists?("#{app_path}/public/assets/application.js")
  90 + assert File.exists?("#{app_path}/public/assets/application.css")
  91 + assert !File.exists?("#{app_path}/public/assets/something.min.js")
  92 + assert !File.exists?("#{app_path}/public/assets/something.min.css")
  93 + end
  94 +
67 95 test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
68 96 add_to_config "config.assets.digest = true"
69 97 add_to_config "config.action_controller.perform_caching = false"

0 comments on commit 082f53a

Please sign in to comment.
Something went wrong with that request. Please try again.