aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-09-30 14:46:06 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-09-30 14:55:23 -0700
commit19987b64af0d543a6292c3fd9b0b877f70eab306 (patch)
tree5f461667b3017b46c8b1c166169912b229c20888 /actionpack
parent5cb5092a70e97d64c5df6fa899548ba44d1d066e (diff)
downloadrails-19987b64af0d543a6292c3fd9b0b877f70eab306.tar.gz
rails-19987b64af0d543a6292c3fd9b0b877f70eab306.tar.bz2
rails-19987b64af0d543a6292c3fd9b0b877f70eab306.zip
Asset manifest includes aliases for foo.js -> foo/index.js and vice versa. Bump Sprockets requirements from 2.1+ to 2.2+ and let it answer "should we compile this asset?" for us.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md14
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--actionpack/lib/sprockets/static_compiler.rb32
3 files changed, 27 insertions, 21 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 69937accf2..fe0c7c40d9 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,19 @@
## Rails 3.2.9 (unreleased) ##
+* Precompiled assets include aliases from foo.js to foo/index.js and vice versa.
+
+ # Precompiles phone-<digest>.css and aliases phone/index.css to phone.css.
+ config.assets.precompile = [ 'phone.css' ]
+
+ # Precompiles phone/index-<digest>.css and aliases phone.css to phone/index.css.
+ config.assets.precompile = [ 'phone/index.css' ]
+
+ # Both of these work with either precompile thanks to their aliases.
+ <%= stylesheet_link_tag 'phone', media: 'all' %>
+ <%= stylesheet_link_tag 'phone/index', media: 'all' %>
+
+ *Jeremy Kemper*
+
* `assert_template` is no more passing with what ever string that matches
with the template name.
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 3d67541557..002351696d 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency('rack', '~> 1.4.0')
s.add_dependency('rack-test', '~> 0.6.1')
s.add_dependency('journey', '~> 1.0.4')
- s.add_dependency('sprockets', '~> 2.1')
+ s.add_dependency('sprockets', '~> 2.2')
s.add_dependency('erubis', '~> 2.7.0')
s.add_development_dependency('tzinfo', '~> 0.3.29')
diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb
index 2e2db4b760..4341a27d5d 100644
--- a/actionpack/lib/sprockets/static_compiler.rb
+++ b/actionpack/lib/sprockets/static_compiler.rb
@@ -15,13 +15,11 @@ module Sprockets
def compile
manifest = {}
- 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)
+ env.each_logical_path(paths) do |logical_path|
if asset = env.find_asset(logical_path)
- manifest[logical_path] = write_asset(asset)
+ digest_path = write_asset(asset)
+ manifest[asset.logical_path] = digest_path
+ manifest[aliased_path_for(asset.logical_path)] = digest_path
end
end
write_manifest(manifest) if @manifest
@@ -43,22 +41,16 @@ module Sprockets
end
end
- def compile_path?(logical_path)
- paths.each do |path|
- case path
- when Regexp
- return true if path.match(logical_path)
- when Proc
- return true if path.call(logical_path)
- else
- return true if File.fnmatch(path.to_s, logical_path)
- end
- end
- false
- end
-
def path_for(asset)
@digest ? asset.digest_path : asset.logical_path
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