aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-09-24 03:05:36 +0200
committerJosé Valim <jose.valim@gmail.com>2011-09-24 03:17:49 +0200
commite69011521da0a9d4559436da21ea030465e54d08 (patch)
treef77a1494a3533bf70a6340a7cfd6d508e942b905
parente9b02ae27a837d7ba02681e225590f55ce02af8c (diff)
downloadrails-e69011521da0a9d4559436da21ea030465e54d08.tar.gz
rails-e69011521da0a9d4559436da21ea030465e54d08.tar.bz2
rails-e69011521da0a9d4559436da21ea030465e54d08.zip
Avoid using pathnames and automatically create the manifest directory if one does not exist yet.
-rw-r--r--actionpack/lib/sprockets/assets.rake11
-rw-r--r--actionpack/lib/sprockets/static_compiler.rb5
-rw-r--r--railties/test/application/assets_test.rb4
3 files changed, 11 insertions, 9 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 782ea38991..12b954371a 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -8,10 +8,15 @@ namespace :assets do
ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
+ require "fileutils"
Rake::Task["tmp:cache:clear"].invoke
Rails.application.initialize!(:assets)
Sprockets::Bootstrap.new(Rails.application).run
+ unless Rails.application.config.assets.enabled
+ raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
+ end
+
# Ensure that action view is loaded and the appropriate sprockets hooks get executed
ActionView::Base
@@ -20,11 +25,13 @@ namespace :assets do
config = Rails.application.config
env = Rails.application.assets
- target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
- manifest_path = config.assets.manifest || target
+ target = File.join(Rails.public_path, config.assets.prefix)
static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)
+
manifest = static_compiler.precompile(config.assets.precompile)
+ manifest_path = config.assets.manifest || target
+ FileUtils.mkdir_p(manifest_path)
File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
YAML.dump(manifest, f)
diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb
index fa4f9451df..4a0078be46 100644
--- a/actionpack/lib/sprockets/static_compiler.rb
+++ b/actionpack/lib/sprockets/static_compiler.rb
@@ -1,5 +1,4 @@
require 'fileutils'
-require 'pathname'
module Sprockets
class StaticCompiler
@@ -26,8 +25,8 @@ module Sprockets
def compile(asset)
asset_path = digest_asset(asset)
- filename = target.join(asset_path)
- FileUtils.mkdir_p filename.dirname
+ filename = File.join(target, asset_path)
+ FileUtils.mkdir_p File.dirname(filename)
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
asset_path
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 85320ccba5..e9985fa643 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -123,7 +123,6 @@ module ApplicationTests
add_to_config "config.assets.digest = true"
precompile!
-
manifest = "#{app_path}/public/assets/manifest.yml"
assets = YAML.load_file(manifest)
@@ -137,10 +136,8 @@ module ApplicationTests
# digest is default in false, we must enable it for test environment
add_to_config "config.assets.digest = true"
add_to_config "config.assets.manifest = '#{app_path}/shared'"
- FileUtils.mkdir "#{app_path}/shared"
precompile!
-
manifest = "#{app_path}/shared/manifest.yml"
assets = YAML.load_file(manifest)
@@ -148,7 +145,6 @@ module ApplicationTests
assert_match(/application-([0-z]+)\.css/, assets["application.css"])
end
-
test "the manifest file should be saved by default in the same assets folder" do
app_file "app/assets/javascripts/application.js", "alert();"
# digest is default in false, we must enable it for test environment