Skip to content

Commit

Permalink
packr integration
Browse files Browse the repository at this point in the history
git-svn-id: http://bundle-fu.googlecode.com/svn/trunk@62 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information
timcharper committed Oct 31, 2007
1 parent b7ecbb8 commit f99b8b9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/bundle_fu.rb
Expand Up @@ -27,7 +27,12 @@ def bundle_js_files(filenames=[], options={})
output = ""
bundle_files(filenames) { |filename, content|
if options[:compress]
JSMinimizer.minimize_content(content)
if Object.const_defined?("Packr")
# use Packr plugin (http://blog.jcoglan.com/packr/)
Packr.new.pack(content, options[:packr_options] || {:shrink_vars => false, :base62 => true})
else
JSMinimizer.minimize_content(content)
end
else
content
end
Expand Down
25 changes: 25 additions & 0 deletions test/functional/bundle_fu_test.rb
Expand Up @@ -20,6 +20,31 @@ def test__bundle_js_files__should_include_js_content
assert_public_files_match("/javascripts/cache/bundle.js", "function js_1()")
end

def test__bundle_js_files__should_use_packr
Object.send :class_eval, <<EOF
class ::Object::Packr
def initialize
end
def pack(content, options={})
"PACKR!" + options.inspect
end
end
EOF

@mock_view.bundle() { @@content_include_all }
assert_public_files_match("/javascripts/cache/bundle.js", "PACKR")
purge_cache

@mock_view.bundle(:packr_options => {:packr_options_here => "hi_packr"}) { @@content_include_all }
assert_public_files_match("/javascripts/cache/bundle.js", "packr_options_here", "Should include packr_options")


Object.send :remove_const, "Packr"

end

def test__bundle_js_files__should_default_to_not_compressed_and_include_override_option
@mock_view.bundle() { @@content_include_all }
default_content = File.read(public_file("/javascripts/cache/bundle.js"))
Expand Down

0 comments on commit f99b8b9

Please sign in to comment.