Skip to content

Commit

Permalink
CoC: if you are precompiling you want a manifest.yml, if you have a m…
Browse files Browse the repository at this point in the history
…anifest.yml you want use it and don't fallback to live compiling
  • Loading branch information
guilleiguaran committed Aug 30, 2011
1 parent 27ac20d commit e43fa07
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
6 changes: 2 additions & 4 deletions actionpack/lib/sprockets/assets.rake
Expand Up @@ -46,10 +46,8 @@ namespace :assets do
env.precompile(*assets)
end

if config.assets.manifest
File.open("#{target}/manifest.yml", 'w') do |f|
YAML.dump(manifest, f)
end
File.open("#{target}/manifest.yml", 'w') do |f|
YAML.dump(manifest, f)
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Expand Up @@ -108,14 +108,12 @@ def asset_for(source, ext)
end

def digest_for(logical_path)
if asset_digests && (digest = asset_digests[logical_path])
if asset_digests
digest = asset_digests[logical_path]
raise AssetNotPrecompiledError unless digest
return digest
end

if digest.nil? && Rails.application.config.assets.precompile_only
raise AssetNotPrecompiledError
end

if asset = asset_environment[logical_path]
return asset.digest_path
end
Expand Down
6 changes: 2 additions & 4 deletions actionpack/lib/sprockets/railtie.rb
Expand Up @@ -26,10 +26,8 @@ class Railtie < ::Rails::Railtie
end
end

if config.assets.manifest
if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
config.assets.digests = YAML.load_file(path)
end
if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
config.assets.digests = YAML.load_file(path)
end

ActiveSupport.on_load(:action_view) do
Expand Down
2 changes: 0 additions & 2 deletions railties/lib/rails/application/configuration.rb
Expand Up @@ -42,8 +42,6 @@ def initialize(*)
@assets.version = ''
@assets.debug = false
@assets.allow_debugging = false
@assets.manifest = true
@assets.precompile_only = false
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
Expand Down
Expand Up @@ -52,10 +52,6 @@ class Application < Rails::Application
<% unless options.skip_sprockets? -%>
# Enable the asset pipeline
config.assets.enabled = true

# Create a manifest with the hashes of your assets when you run "rake assets:precompile".
# Use this if you don't have a JavaScript engine in your production servers
config.assets.manifest = true
<% end -%>
end
end
26 changes: 10 additions & 16 deletions railties/test/application/assets_test.rb
Expand Up @@ -62,18 +62,7 @@ def app
end
end

test "precompile don't create a manifest file when manifest option is off" do
app_file "app/assets/javascripts/application.js", "alert();"
app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = false"

capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end

assert !File.exist?("#{app_path}/public/assets/manifest.yml")
end

test "precompile creates a manifest file with all the assets listed when manifest option is on" do
test "precompile creates a manifest file with all the assets listed" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
app_file "app/assets/javascripts/application.js", "alert();"

Expand All @@ -88,7 +77,7 @@ def app
assert_match /application-([0-z]+)\.css/, assets["application.css"]
end

test "assets do not require any assets group gem when manifest option is on and manifest file is present" do
test "assets do not require any assets group gem when manifest file is present" do
app_file "app/assets/javascripts/application.js", "alert();"

ENV["RAILS_ENV"] = "production"
Expand All @@ -108,10 +97,8 @@ def app
assert !defined?(Uglifier)
end

test "assets raise AssetNotPrecompiledError if config.assets.precompile_only is on and file isn't precompiled" do
app_file "app/assets/javascripts/app.js", "alert();"
test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do
app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
app_file "config/initializers/precompile_only.rb", "Rails.application.config.assets.precompile_only = true"

app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
Expand All @@ -120,6 +107,13 @@ def app
RUBY

ENV["RAILS_ENV"] = "production"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end

# Create file after of precompile
app_file "app/assets/javascripts/app.js", "alert();"

require "#{app_path}/config/environment"
class ::PostsController < ActionController::Base ; end

Expand Down

0 comments on commit e43fa07

Please sign in to comment.