sprockets-rails 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.rdoc +3 -0
  3. data/Rakefile +15 -31
  4. data/lib/sprockets/rails/bootstrap.rb +41 -0
  5. data/lib/sprockets/rails/compressors.rb +87 -0
  6. data/lib/sprockets/rails/helpers/isolated_helper.rb +15 -0
  7. data/lib/sprockets/rails/helpers/rails_helper.rb +169 -0
  8. data/lib/sprockets/rails/helpers.rb +8 -0
  9. data/lib/sprockets/rails/railtie.rb +64 -0
  10. data/lib/sprockets/rails/static_compiler.rb +64 -0
  11. data/lib/sprockets/rails/version.rb +5 -0
  12. data/lib/sprockets-rails.rb +5 -6
  13. data/lib/tasks/assets.rake +105 -0
  14. data/test/abstract_unit.rb +145 -0
  15. data/test/assets_debugging_test.rb +65 -0
  16. data/test/assets_test.rb +532 -0
  17. data/test/fixtures/alternate/stylesheets/style.css +1 -0
  18. data/{generators/sprockets_rails/templates/application.js → test/fixtures/app/fonts/dir/font.ttf} +0 -0
  19. data/test/fixtures/app/fonts/font.ttf +0 -0
  20. data/test/fixtures/app/images/logo.png +0 -0
  21. data/test/fixtures/app/javascripts/application.js +1 -0
  22. data/test/fixtures/app/javascripts/dir/xmlhr.js +0 -0
  23. data/test/fixtures/app/javascripts/extra.js +0 -0
  24. data/test/fixtures/app/javascripts/xmlhr.js +0 -0
  25. data/test/fixtures/app/stylesheets/application.css +1 -0
  26. data/test/fixtures/app/stylesheets/dir/style.css +0 -0
  27. data/test/fixtures/app/stylesheets/extra.css +0 -0
  28. data/test/fixtures/app/stylesheets/style.css +0 -0
  29. data/test/sprockets_compressors_test.rb +27 -0
  30. data/test/sprockets_helper_test.rb +345 -0
  31. data/test/sprockets_helper_with_routes_test.rb +60 -0
  32. data/test/test_helper.rb +84 -0
  33. metadata +116 -65
  34. data/.gitignore +0 -5
  35. data/README.textile +0 -91
  36. data/VERSION +0 -1
  37. data/config/sprockets.yml +0 -10
  38. data/generators/sprockets_rails/sprockets_rails_generator.rb +0 -13
  39. data/init.rb +0 -1
  40. data/install.rb +0 -13
  41. data/lib/sprocket.rb +0 -74
  42. data/lib/sprockets_application.rb +0 -8
  43. data/lib/sprockets_controller.rb +0 -12
  44. data/lib/sprockets_helper.rb +0 -9
  45. data/recipes/sprockets_tasks.rb +0 -17
  46. data/sprockets-rails.gemspec +0 -60
  47. data/tasks/sprockets_tasks.rake +0 -27
  48. data/test/sprockets_test.rb +0 -8
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Sam Stephenson
1
+ Copyright (c) 2012 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = sprockets-rails
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile CHANGED
@@ -1,40 +1,24 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ #!/usr/bin/env rake
3
2
  require 'rake/testtask'
4
- require 'rake/rdoctask'
5
3
 
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "sprockets-rails"
10
- gem.summary = %Q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
11
- gem.description = %Q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
12
- gem.email = "jeff@80beans.com"
13
- gem.homepage = "http://github.com/80beans/sprockets-rails"
14
- gem.authors = ["Sam Stephenson","Jeff Kreeftmeijer"]
15
- gem.add_dependency 'sprockets', ">= 1.0.2"
4
+ namespace :test do
5
+ task :isolated do
6
+ Dir["test/assets*_test.rb"].each do |file|
7
+ dash_i = [
8
+ 'test',
9
+ 'lib',
10
+ ]
11
+ ruby "-I#{dash_i.join ':'}", file
12
+ end
16
13
  end
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
14
  end
20
15
 
21
- desc 'Default: run unit tests.'
22
- task :default => :test
23
-
24
- desc 'Test the sprockets plugin.'
25
- Rake::TestTask.new(:test) do |t|
16
+ Rake::TestTask.new("test:regular") do |t|
26
17
  t.libs << 'lib'
27
- t.pattern = 'test/**/*_test.rb'
18
+ t.libs << 'test'
19
+ t.pattern = 'test/**/sprockets*_test.rb'
28
20
  t.verbose = true
29
21
  end
30
22
 
31
- desc 'Generate documentation for the sprockets plugin.'
32
- Rake::RDocTask.new(:rdoc) do |rdoc|
33
- rdoc.rdoc_dir = 'rdoc'
34
- rdoc.title = 'Sprockets'
35
- rdoc.options << '--line-numbers' << '--inline-source'
36
- rdoc.rdoc_files.include('README')
37
- rdoc.rdoc_files.include('lib/**/*.rb')
38
- end
39
-
40
- Jeweler::GemcutterTasks.new
23
+ task :test => ['test:isolated', 'test:regular']
24
+ task :default => :test
@@ -0,0 +1,41 @@
1
+ module Sprockets
2
+ module Rails
3
+ class Bootstrap
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ # TODO: Get rid of config.assets.enabled
9
+ def run
10
+ app, config = @app, @app.config
11
+ return unless app.assets
12
+
13
+ config.assets.paths.each { |path| app.assets.append_path(path) }
14
+
15
+ if config.assets.compress
16
+ # temporarily hardcode default JS compressor to uglify. Soon, it will work
17
+ # the same as SCSS, where a default plugin sets the default.
18
+ unless config.assets.js_compressor == false
19
+ js_compressor = config.assets.js_compressor || :uglifier
20
+ app.assets.js_compressor = LazyCompressor.new { Sprockets::Rails::Compressors.registered_js_compressor(js_compressor) }
21
+ end
22
+
23
+ unless config.assets.css_compressor == false
24
+ css_compressor = config.assets.css_compressor
25
+ app.assets.css_compressor = LazyCompressor.new { Sprockets::Rails::Compressors.registered_css_compressor(css_compressor) }
26
+ end
27
+ end
28
+
29
+ if config.assets.compile
30
+ app.routes.prepend do
31
+ mount app.assets => config.assets.prefix
32
+ end
33
+ end
34
+
35
+ if config.assets.digest
36
+ app.assets = app.assets.index
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,87 @@
1
+ module Sprockets
2
+ module Rails
3
+ module Compressors
4
+ extend self
5
+
6
+ @@css_compressors = {}
7
+ @@js_compressors = {}
8
+ @@default_css_compressor = nil
9
+ @@default_js_compressor = nil
10
+
11
+ def register_css_compressor(name, klass, options = {})
12
+ @@default_css_compressor = name.to_sym if options[:default] || @@default_css_compressor.nil?
13
+ @@css_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] }
14
+ end
15
+
16
+ def register_js_compressor(name, klass, options = {})
17
+ @@default_js_compressor = name.to_sym if options[:default] || @@default_js_compressor.nil?
18
+ @@js_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] }
19
+ end
20
+
21
+ def registered_css_compressor(name)
22
+ find_registered_compressor name, @@css_compressors, @@default_css_compressor
23
+ end
24
+
25
+ def registered_js_compressor(name)
26
+ find_registered_compressor name, @@js_compressors, @@default_js_compressor
27
+ end
28
+
29
+ # The default compressors must be registered in default plugins (ex. Sass-Rails)
30
+ register_css_compressor(:scss, 'Sass::Rails::Compressor', :require => 'sass/rails/compressor', :default => true)
31
+ register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier', :default => true)
32
+
33
+ # Automaticaly register some compressors
34
+ register_css_compressor(:yui, 'YUI::CssCompressor', :require => 'yui/compressor')
35
+ register_js_compressor(:closure, 'Closure::Compiler', :require => 'closure-compiler')
36
+ register_js_compressor(:yui, 'YUI::JavaScriptCompressor', :require => 'yui/compressor')
37
+
38
+ private
39
+
40
+ def find_registered_compressor(name, compressors_hash, default_compressor_name)
41
+ if name.respond_to?(:to_sym)
42
+ compressor = compressors_hash[name.to_sym] || compressors_hash[default_compressor_name]
43
+ require compressor[:require] if compressor[:require]
44
+ compressor[:klass].constantize.new
45
+ else
46
+ name
47
+ end
48
+ end
49
+ end
50
+
51
+ # An asset compressor which does nothing.
52
+ #
53
+ # This compressor simply returns the asset as-is, without any compression
54
+ # whatsoever. It is useful in development mode, when compression isn't
55
+ # needed but using the same asset pipeline as production is desired.
56
+ class NullCompressor #:nodoc:
57
+ def compress(content)
58
+ content
59
+ end
60
+ end
61
+
62
+ # An asset compressor which only initializes the underlying compression
63
+ # engine when needed.
64
+ #
65
+ # This postpones the initialization of the compressor until
66
+ # <code>#compress</code> is called the first time.
67
+ class LazyCompressor #:nodoc:
68
+ # Initializes a new LazyCompressor.
69
+ #
70
+ # The block should return a compressor when called, i.e. an object
71
+ # which responds to <code>#compress</code>.
72
+ def initialize(&block)
73
+ @block = block
74
+ end
75
+
76
+ def compress(content)
77
+ compressor.compress(content)
78
+ end
79
+
80
+ private
81
+
82
+ def compressor
83
+ @compressor ||= (@block.call || NullCompressor.new)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,15 @@
1
+ module Sprockets
2
+ module Rails
3
+ module Helpers
4
+ module IsolatedHelper
5
+ def controller
6
+ nil
7
+ end
8
+
9
+ def config
10
+ ::Rails.application.config.action_controller
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,169 @@
1
+ require "action_view"
2
+
3
+ module Sprockets
4
+ module Rails
5
+ module Helpers
6
+ module RailsHelper
7
+ extend ActiveSupport::Concern
8
+ include ActionView::Helpers::AssetTagHelper
9
+
10
+ def asset_paths
11
+ @asset_paths ||= begin
12
+ paths = RailsHelper::AssetPaths.new(config, controller)
13
+ paths.asset_environment = asset_environment
14
+ paths.asset_digests = asset_digests
15
+ paths.compile_assets = compile_assets?
16
+ paths.digest_assets = digest_assets?
17
+ paths
18
+ end
19
+ end
20
+
21
+ def javascript_include_tag(*sources)
22
+ options = sources.extract_options!
23
+ debug = options.delete(:debug) { debug_assets? }
24
+ body = options.delete(:body) { false }
25
+ digest = options.delete(:digest) { digest_assets? }
26
+
27
+ sources.collect do |source|
28
+ if debug && asset = asset_paths.asset_for(source, 'js')
29
+ asset.to_a.map { |dep|
30
+ super(dep.pathname.to_s, { :src => path_to_asset(dep, :ext => 'js', :body => true, :digest => digest) }.merge!(options))
31
+ }
32
+ else
33
+ super(source.to_s, { :src => path_to_asset(source, :ext => 'js', :body => body, :digest => digest) }.merge!(options))
34
+ end
35
+ end.join("\n").html_safe
36
+ end
37
+
38
+ def stylesheet_link_tag(*sources)
39
+ options = sources.extract_options!
40
+ debug = options.delete(:debug) { debug_assets? }
41
+ body = options.delete(:body) { false }
42
+ digest = options.delete(:digest) { digest_assets? }
43
+
44
+ sources.collect do |source|
45
+ if debug && asset = asset_paths.asset_for(source, 'css')
46
+ asset.to_a.map { |dep|
47
+ super(dep.pathname.to_s, { :href => path_to_asset(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) }.merge!(options))
48
+ }
49
+ else
50
+ super(source.to_s, { :href => path_to_asset(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) }.merge!(options))
51
+ end
52
+ end.join("\n").html_safe
53
+ end
54
+
55
+ def asset_path(source, options = {})
56
+ source = source.logical_path if source.respond_to?(:logical_path)
57
+ path = asset_paths.compute_public_path(source, asset_prefix, options.merge(:body => true))
58
+ options[:body] ? "#{path}?body=1" : path
59
+ end
60
+ alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with an asset_path named route
61
+
62
+ def image_path(source)
63
+ path_to_asset(source)
64
+ end
65
+ alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
66
+
67
+ def font_path(source)
68
+ path_to_asset(source)
69
+ end
70
+ alias_method :path_to_font, :font_path # aliased to avoid conflicts with an font_path named route
71
+
72
+ def javascript_path(source)
73
+ path_to_asset(source, :ext => 'js')
74
+ end
75
+ alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with an javascript_path named route
76
+
77
+ def stylesheet_path(source)
78
+ path_to_asset(source, :ext => 'css')
79
+ end
80
+ alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with an stylesheet_path named route
81
+
82
+ private
83
+ def debug_assets?
84
+ compile_assets? && (::Rails.application.config.assets.debug || params[:debug_assets])
85
+ rescue NameError
86
+ false
87
+ end
88
+
89
+ # Override to specify an alternative prefix for asset path generation.
90
+ # When combined with a custom +asset_environment+, this can be used to
91
+ # implement themes that can take advantage of the asset pipeline.
92
+ #
93
+ # If you only want to change where the assets are mounted, refer to
94
+ # +config.assets.prefix+ instead.
95
+ def asset_prefix
96
+ ::Rails.application.config.assets.prefix
97
+ end
98
+
99
+ def asset_digests
100
+ ::Rails.application.config.assets.digests
101
+ end
102
+
103
+ def compile_assets?
104
+ ::Rails.application.config.assets.compile
105
+ end
106
+
107
+ def digest_assets?
108
+ ::Rails.application.config.assets.digest
109
+ end
110
+
111
+ # Override to specify an alternative asset environment for asset
112
+ # path generation. The environment should already have been mounted
113
+ # at the prefix returned by +asset_prefix+.
114
+ def asset_environment
115
+ ::Rails.application.assets
116
+ end
117
+
118
+ class AssetPaths < ::ActionView::AssetPaths #:nodoc:
119
+ attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, :digest_assets
120
+
121
+ class AssetNotPrecompiledError < StandardError; end
122
+
123
+ def asset_for(source, ext)
124
+ source = source.to_s
125
+ return nil if is_uri?(source)
126
+ source = rewrite_extension(source, nil, ext)
127
+ asset_environment[source]
128
+ rescue Sprockets::FileOutsidePaths
129
+ nil
130
+ end
131
+
132
+ def digest_for(logical_path)
133
+ if digest_assets && asset_digests && (digest = asset_digests[logical_path])
134
+ return digest
135
+ end
136
+
137
+ if compile_assets
138
+ if digest_assets && asset = asset_environment[logical_path]
139
+ return asset.digest_path
140
+ end
141
+ return logical_path
142
+ else
143
+ raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
144
+ end
145
+ end
146
+
147
+ def rewrite_asset_path(source, dir, options = {})
148
+ if source[0] == ?/
149
+ source
150
+ else
151
+ source = digest_for(source) unless options[:digest] == false
152
+ source = File.join(dir, source)
153
+ source = "/#{source}" unless source =~ /^\//
154
+ source
155
+ end
156
+ end
157
+
158
+ def rewrite_extension(source, dir, ext)
159
+ if ext && File.extname(source) != ".#{ext}"
160
+ "#{source}.#{ext}"
161
+ else
162
+ source
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,8 @@
1
+ module Sprockets
2
+ module Rails
3
+ module Helpers
4
+ autoload :RailsHelper, "sprockets/rails/helpers/rails_helper"
5
+ autoload :IsolatedHelper, "sprockets/rails/helpers/isolated_helper"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,64 @@
1
+ require "action_controller/railtie"
2
+
3
+ module Sprockets
4
+ module Rails
5
+ autoload :Bootstrap, "sprockets/rails/bootstrap"
6
+ autoload :Helpers, "sprockets/rails/helpers"
7
+ autoload :Compressors, "sprockets/rails/compressors"
8
+ autoload :LazyCompressor, "sprockets/rails/compressors"
9
+ autoload :NullCompressor, "sprockets/rails/compressors"
10
+ autoload :StaticCompiler, "sprockets/rails/static_compiler"
11
+
12
+ # TODO: Get rid of config.assets.enabled
13
+ class Railtie < ::Rails::Railtie
14
+ rake_tasks do
15
+ load "tasks/assets.rake"
16
+ end
17
+
18
+ initializer "sprockets.environment", :group => :all do |app|
19
+ config = app.config
20
+ next unless config.assets.enabled
21
+
22
+ require 'sprockets'
23
+
24
+ app.assets = Sprockets::Environment.new(app.root.to_s) do |env|
25
+ env.version = ::Rails.env + "-#{config.assets.version}"
26
+
27
+ if config.assets.logger != false
28
+ env.logger = config.assets.logger || ::Rails.logger
29
+ end
30
+
31
+ if config.assets.cache_store != false
32
+ env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache
33
+ end
34
+ end
35
+
36
+ if config.assets.manifest
37
+ path = File.join(config.assets.manifest, "manifest.yml")
38
+ else
39
+ path = File.join(::Rails.public_path, config.assets.prefix, "manifest.yml")
40
+ end
41
+
42
+ if File.exist?(path)
43
+ config.assets.digests = YAML.load_file(path)
44
+ end
45
+
46
+ ActiveSupport.on_load(:action_view) do
47
+ include ::Sprockets::Rails::Helpers::RailsHelper
48
+ app.assets.context_class.instance_eval do
49
+ include ::Sprockets::Rails::Helpers::IsolatedHelper
50
+ include ::Sprockets::Rails::Helpers::RailsHelper
51
+ end
52
+ end
53
+ end
54
+
55
+ # We need to configure this after initialization to ensure we collect
56
+ # paths from all engines. This hook is invoked exactly before routes
57
+ # are compiled, and so that other Railties have an opportunity to
58
+ # register compressors.
59
+ config.after_initialize do |app|
60
+ Sprockets::Rails::Bootstrap.new(app).run
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+
3
+ module Sprockets
4
+ module Rails
5
+ class StaticCompiler
6
+ attr_accessor :env, :target, :paths
7
+
8
+ def initialize(env, target, paths, options = {})
9
+ @env = env
10
+ @target = target
11
+ @paths = paths
12
+ @digest = options.fetch(:digest, true)
13
+ @manifest = options.fetch(:manifest, true)
14
+ @manifest_path = options.delete(:manifest_path) || target
15
+ @zip_files = options.delete(:zip_files) || /\.(?:css|html|js|svg|txt|xml)$/
16
+ end
17
+
18
+ def compile
19
+ manifest = {}
20
+ env.each_logical_path do |logical_path|
21
+ next unless compile_path?(logical_path)
22
+ if asset = env.find_asset(logical_path)
23
+ manifest[logical_path] = write_asset(asset)
24
+ end
25
+ end
26
+ write_manifest(manifest) if @manifest
27
+ end
28
+
29
+ def write_manifest(manifest)
30
+ FileUtils.mkdir_p(@manifest_path)
31
+ File.open("#{@manifest_path}/manifest.yml", 'wb') do |f|
32
+ YAML.dump(manifest, f)
33
+ end
34
+ end
35
+
36
+ def write_asset(asset)
37
+ path_for(asset).tap do |path|
38
+ filename = File.join(target, path)
39
+ FileUtils.mkdir_p File.dirname(filename)
40
+ asset.write_to(filename)
41
+ asset.write_to("#{filename}.gz") if filename.to_s =~ @zip_files
42
+ end
43
+ end
44
+
45
+ def compile_path?(logical_path)
46
+ paths.each do |path|
47
+ case path
48
+ when Regexp
49
+ return true if path.match(logical_path)
50
+ when Proc
51
+ return true if path.call(logical_path)
52
+ else
53
+ return true if File.fnmatch(path.to_s, logical_path)
54
+ end
55
+ end
56
+ false
57
+ end
58
+
59
+ def path_for(asset)
60
+ @digest ? asset.digest_path : asset.logical_path
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -1,8 +1,7 @@
1
- require "sprockets"
2
- require "sprockets_helper"
3
- require "sprocket"
4
- require "sprockets_application"
1
+ require 'sprockets'
2
+ require 'sprockets/rails/railtie'
5
3
 
6
- class ActionController::Base
7
- helper :sprockets
4
+ module Sprockets
5
+ module Rails
6
+ end
8
7
  end
@@ -0,0 +1,105 @@
1
+ require "fileutils"
2
+
3
+ namespace :assets do
4
+ def ruby_rake_task(task, fork = true)
5
+ env = ENV['RAILS_ENV'] || 'production'
6
+ groups = ENV['RAILS_GROUPS'] || 'assets'
7
+ args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
8
+ args << "--trace" if Rake.application.options.trace
9
+ if $0 =~ /rake\.bat\Z/i
10
+ Kernel.exec $0, *args
11
+ else
12
+ fork ? ruby(*args) : Kernel.exec(FileUtils::RUBY, *args)
13
+ end
14
+ end
15
+
16
+ # We are currently running with no explicit bundler group
17
+ # and/or no explicit environment - we have to reinvoke rake to
18
+ # execute this task.
19
+ def invoke_or_reboot_rake_task(task)
20
+ if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty?
21
+ ruby_rake_task task
22
+ else
23
+ Rake::Task[task].invoke
24
+ end
25
+ end
26
+
27
+ desc "Compile all the assets named in config.assets.precompile"
28
+ task :precompile do
29
+ invoke_or_reboot_rake_task "assets:precompile:all"
30
+ end
31
+
32
+ namespace :precompile do
33
+ def internal_precompile(digest=nil)
34
+ unless ::Rails.application.config.assets.enabled
35
+ warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
36
+ exit
37
+ end
38
+
39
+ # Ensure that action view is loaded and the appropriate
40
+ # sprockets hooks get executed
41
+ _ = ActionView::Base
42
+
43
+ config = ::Rails.application.config
44
+ config.assets.compile = true
45
+ config.assets.digest = digest unless digest.nil?
46
+ config.assets.digests = {}
47
+
48
+ env = ::Rails.application.assets
49
+ target = File.join(::Rails.public_path, config.assets.prefix)
50
+ compiler = Sprockets::Rails::StaticCompiler.new(env,
51
+ target,
52
+ config.assets.precompile,
53
+ :manifest_path => config.assets.manifest,
54
+ :digest => config.assets.digest,
55
+ :manifest => digest.nil?)
56
+ compiler.compile
57
+ end
58
+
59
+ task :all do
60
+ Rake::Task["assets:precompile:primary"].invoke
61
+ # We need to reinvoke in order to run the secondary digestless
62
+ # asset compilation run - a fresh Sprockets environment is
63
+ # required in order to compile digestless assets as the
64
+ # environment has already cached the assets on the primary
65
+ # run.
66
+ ruby_rake_task("assets:precompile:nondigest", false) if ::Rails.application.config.assets.digest
67
+ end
68
+
69
+ task :primary => ["assets:cache:clean"] do
70
+ internal_precompile
71
+ end
72
+
73
+ task :nondigest => ["assets:cache:clean"] do
74
+ internal_precompile(false)
75
+ end
76
+ end
77
+
78
+ desc "Remove compiled assets"
79
+ task :clean do
80
+ invoke_or_reboot_rake_task "assets:clean:all"
81
+ end
82
+
83
+ namespace :clean do
84
+ task :all => ["assets:cache:clean"] do
85
+ config = ::Rails.application.config
86
+ public_asset_path = File.join(::Rails.public_path, config.assets.prefix)
87
+ rm_rf public_asset_path, :secure => true
88
+ end
89
+ end
90
+
91
+ namespace :cache do
92
+ task :clean => ["assets:environment"] do
93
+ ::Rails.application.assets.cache.clear
94
+ end
95
+ end
96
+
97
+ task :environment do
98
+ if ::Rails.application.config.assets.initialize_on_precompile
99
+ Rake::Task["environment"].invoke
100
+ else
101
+ ::Rails.application.initialize!(:assets)
102
+ Sprockets::Rails::Bootstrap.new(Rails.application).run
103
+ end
104
+ end
105
+ end