Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow manifest to be lazily set

  • Loading branch information...
commit 0fa3cc813d21495b96c056181336e200f001c664 1 parent f9b9434
@josh josh authored
Showing with 23 additions and 1 deletion.
  1. +6 −1 lib/rake/sprocketstask.rb
  2. +17 −0 test/test_rake_task.rb
View
7 lib/rake/sprocketstask.rb
@@ -47,7 +47,11 @@ def index
# Will be created by default if an environment and output
# directory are given
def manifest
- @manifest ||= Sprockets::Manifest.new(index, output)
+ if !@manifest.is_a?(Sprockets::Manifest) && @manifest.respond_to?(:call)
+ @manifest = @manifest.call
+ else
+ @manifest
+ end
end
attr_writer :manifest
@@ -93,6 +97,7 @@ def log_level=(level)
def initialize(name = :assets)
@name = name
@environment = lambda { Sprockets::Environment.new(Dir.pwd) }
+ @manifest = lambda { Sprockets::Manifest.new(index, output) }
@logger = Logger.new($stderr)
@logger.level = Logger::INFO
@keep = 2
View
17 test/test_rake_task.rb
@@ -69,4 +69,21 @@ def teardown
assert Dir["#{@dir}/manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
+
+ test "lazy custom manifest" do
+ Rake::SprocketsTask.new do |t|
+ t.environment = nil
+ t.manifest = lambda { @manifest }
+ t.assets = ['application.js']
+ t.log_level = :fatal
+ end
+
+ digest_path = @env['application.js'].digest_path
+ assert !File.exist?("#{@dir}/#{digest_path}")
+
+ @rake[:assets].invoke
+
+ assert Dir["#{@dir}/manifest-*.json"].first
+ assert File.exist?("#{@dir}/#{digest_path}")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.