Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Allow manifest to be lazily set
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Oct 11, 2012
1 parent f9b9434 commit 0fa3cc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rake/sprocketstask.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def index
# Will be created by default if an environment and output # Will be created by default if an environment and output
# directory are given # directory are given
def manifest 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 end
attr_writer :manifest attr_writer :manifest


Expand Down Expand Up @@ -93,6 +97,7 @@ def log_level=(level)
def initialize(name = :assets) def initialize(name = :assets)
@name = name @name = name
@environment = lambda { Sprockets::Environment.new(Dir.pwd) } @environment = lambda { Sprockets::Environment.new(Dir.pwd) }
@manifest = lambda { Sprockets::Manifest.new(index, output) }
@logger = Logger.new($stderr) @logger = Logger.new($stderr)
@logger.level = Logger::INFO @logger.level = Logger::INFO
@keep = 2 @keep = 2
Expand Down
17 changes: 17 additions & 0 deletions test/test_rake_task.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@ def teardown
assert Dir["#{@dir}/manifest-*.json"].first assert Dir["#{@dir}/manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}") assert File.exist?("#{@dir}/#{digest_path}")
end 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 end

0 comments on commit 0fa3cc8

Please sign in to comment.