Skip to content
Browse files

allow assets:precompile task to duplicate, symlink or hardlink assets…

… without a digest when config.assets.digest = true (or, indeed, do nothing)
  • Loading branch information...
1 parent 6161a4e commit 18333d6a16d4138cf8b700a18b829e96c694c785 @mjtko committed
View
22 actionpack/lib/sprockets/assets.rake
@@ -21,6 +21,16 @@ namespace :assets do
target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
manifest = {}
manifest_path = config.assets.manifest || target
+ case config.assets.undigested_as
+ when NilClass
+ undigested_as = :duplicate
+ when :none, false
+ undigested_as = false
+ when :duplicate, :symlink, :hardlink
+ undigested_as = config.assets.undigested_as
+ else
+ raise "config.assets.undigested_as was '#{config.assets.undigested_as.inspect}'; must be one of: :duplicate, :symlink, :hardlink, :none, false"
+ end
config.assets.precompile.each do |path|
env.each_logical_path do |logical_path|
@@ -34,10 +44,20 @@ namespace :assets do
asset_path = config.assets.digest ? asset.digest_path : logical_path
manifest[logical_path] = asset_path
filename = target.join(asset_path)
-
mkdir_p filename.dirname
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
+ if config.assets.digest && undigested_as
+ undigested = target.join(logical_path)
+ case undigested_as
+ when :duplicate
+ asset.write_to(undigested)
+ when :symlink
+ symlink(filename, undigested, :force => true)
+ when :hardlink
+ link(filename, undigested, :force => true)
+ end
+ end
end
end
end
View
1 railties/lib/rails/application/configuration.rb
@@ -47,6 +47,7 @@ def initialize(*)
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
+ @assets.undigested_as = :duplicate
end
def compiled_asset_path
View
4 railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -20,6 +20,10 @@
# Generate digests for assets URLs
config.assets.digest = true
+ # Method to use to additionally create assets without digests
+ # Valid values are :duplicate, :none, :symlink, :hardlink
+ # config.assets.digest = :duplicate
+
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH

0 comments on commit 18333d6

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