Permalink
Browse files

Allow manifest location to be seperated from output directory

  • Loading branch information...
josh committed Oct 16, 2012
1 parent 3f4814f commit a3fe9689a327caaf23d61be923c8f0daf7e75101
Showing with 32 additions and 7 deletions.
  1. +1 −0 README.md
  2. +17 −7 lib/sprockets/manifest.rb
  3. +14 −0 test/test_manifest.rb
View
@@ -363,6 +363,7 @@ submit a pull request.
**2.8.0** (October 16, 2012)
+* Allow manifest location to be seperated from output directory
* Pass logical path and absolute path to each_logical_path iterator
**2.7.0** (October 10, 2012)
View
@@ -29,23 +29,33 @@ def initialize(*args)
@environment = args.shift
end
- unless path = args.shift
- raise ArgumentError, "manifest requires output path"
+ @dir, @path = args[0], args[1]
+
+ # Expand paths
+ @dir = File.expand_path(@dir) if @dir
+ @path = File.expand_path(@path) if @path
+
+ # If path is given as the second arg
+ if @dir && File.extname(@dir) != ""
+ @dir, @path = nil, @dir
end
- if File.extname(path) == ""
- @dir = File.expand_path(path)
+ # Default dir to the directory of the path
+ @dir ||= File.dirname(@path) if @path
+ # If directory is given w/o path, pick a random manifest.json location
+ if @dir && @path.nil?
# Find the first manifest.json in the directory
paths = Dir[File.join(@dir, "manifest*.json")]
if paths.any?
@path = paths.first
else
@path = File.join(@dir, "manifest-#{SecureRandom.hex(16)}.json")
end
- else
- @path = File.expand_path(path)
- @dir = File.dirname(path)
+ end
+
+ unless @dir && @path
+ raise ArgumentError, "manifest requires output path"
end
data = nil
View
@@ -68,6 +68,20 @@ def teardown
assert_equal path, manifest.path
end
+ test "specify manifest directory and seperate location" do
+ root = File.join(Dir::tmpdir, 'public')
+ dir = File.join(root, 'assets')
+ path = File.join(root, 'manifest-123.json')
+
+ system "rm -rf #{root}"
+ assert !File.exist?(root)
+
+ manifest = Sprockets::Manifest.new(@env, dir, path)
+
+ assert_equal dir, manifest.dir
+ assert_equal path, manifest.path
+ end
+
test "compile asset" do
digest_path = @env['application.js'].digest_path

2 comments on commit a3fe968

Contributor

josh replied Oct 16, 2012

@jeremy should make things easier for you.

Sprockets::Manifest.new(env, "./public/assets", "./config/manifest.json")

😁👍

Please sign in to comment.