Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Backport @jeremy's index aliasing commit from Rails 3.2.9, to try to …

…fix issue 9
  • Loading branch information...
commit c3360250493e82d70f6f2078244f76b0177fb330 1 parent 80b86a3
@ndbroadbent authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 lib/turbo-sprockets/sprockets_overrides/static_compiler.rb
View
21 lib/turbo-sprockets/sprockets_overrides/static_compiler.rb
@@ -27,9 +27,6 @@ def compile
start_time = Time.now.to_f
env.each_logical_path do |logical_path|
- if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
- logical_path.sub!(/\/index\./, '.')
- end
next unless compile_path?(logical_path)
# Fetch asset without any processing or compression,
@@ -45,9 +42,15 @@ def compile
!(current_digest_file && File.exists?("#{@target}/#{current_digest_file}"))
if asset = env.find_asset(logical_path)
- @digest_files[logical_path] = write_asset(asset)
+ digest_path = write_asset(asset)
+ @digest_files[asset.logical_path] = digest_path
+
+ # Add 'index' alias if file exists
+ aliased_path = aliased_path_for(asset.logical_path)
+ if File.exists? "#{@target}/#{aliased_path}"
+ @digest_files[aliased_path] = digest_path
+ end
end
-
else
# Set asset file from manifest.yml
digest_file = @current_digest_files[logical_path]
@@ -83,6 +86,14 @@ def compile
def encode_hash_as_utf8(hash)
Hash[*hash.map {|k,v| [k.encode("UTF-8"), v.encode("UTF-8")] }.flatten]
end
+
+ def aliased_path_for(logical_path)
+ if File.basename(logical_path).start_with?('index')
+ logical_path.sub(/\/index([^\/]+)$/, '\1')
+ else
+ logical_path.sub(/\.([^\/]+)$/, '/index.\1')
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.