Browse files

serious bug fix - wasn't working at all, but now it is.

git-svn-id: http://bundle-fu.googlecode.com/svn/trunk@31 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information...
1 parent e24239a commit dd667f767ae36c2f611547b2ebef723d5e7ecdbd timcharper committed Oct 8, 2007
Showing with 28 additions and 6 deletions.
  1. +8 −5 lib/bundle_fu.rb
  2. +1 −1 test/functional/bundle_fu_test.rb
  3. +19 −0 test/functional/css_bundle_test.rb
View
13 lib/bundle_fu.rb
@@ -80,6 +80,9 @@ def bundle(options={}, &block)
:bundle_fu => ( session[:bundle_fu].nil? ? ($bundle_fu.nil? ? true : $bundle_fu) : session[:bundle_fu] )
}.merge(options)
+ # allow them to bypass via parameter
+ options[:bundle_fu] = false if options[:bypass]
+
paths = { :css => options[:css_path], :js => options[:js_path] }
content = capture(&block)
@@ -96,9 +99,9 @@ def bundle(options={}, &block)
content.scan(/(href|src) *= *["']([^"^'^\?]+)/i).each{ |property, value|
case property
when "src"
- js_files[:js] << value
+ new_files[:js] << value
when "href"
- css_files[:css] << value
+ new_files[:css] << value
end
}
end
@@ -120,9 +123,9 @@ def bundle(options={}, &block)
# delete the javascript/css bundle file if it's empty, but keep the filelist cache
FileUtils.rm_f(abs_path)
else
- BundleFu.send("bundle_#{filelist}_files", new_filelist.filenames, output_filename)
-# output = BundleFu.bundle_files(new_filelist.filenames, :type => filetype)
-# File.open( abs_path, "w") {|f| f.puts output } if output
+ # call bundle_css_files or bundle_js_files to bundle all files listed. output it's contents to a file
+ output = BundleFu.send("bundle_#{filetype}_files", new_filelist.filenames, output_filename)
+ File.open( abs_path, "w") {|f| f.puts output } if output
end
new_filelist.save_as(abs_filelist_path)
end
View
2 test/functional/bundle_fu_test.rb
@@ -134,7 +134,7 @@ def test__bypass__should_generate_files_but_render_normal_output
end
def test__bypass_param_set__should_honor_and_store_in_session
- @mock_view.params[:bundle_bypass] = "true"
+ @mock_view.params[:bundle_fu] = "false"
@mock_view.bundle { @@content_include_some }
assert_equal(@@content_include_some, @mock_view.output)
View
19 test/functional/css_bundle_test.rb
@@ -0,0 +1,19 @@
+require File.join(File.dirname(__FILE__), '../test_helper.rb')
+
+class CSSBundleTest < Test::Unit::TestCase
+ def test__rewrite_relative_path__should_rewrite
+ assert_equal("/images/spinner.gif", BundleFu.rewrite_relative_path("/stylesheets/active_scaffold/default/stylesheet.css", "../../../images/spinner.gif"))
+ assert_equal("/images/spinner.gif", BundleFu.rewrite_relative_path("/stylesheets/active_scaffold/default/stylesheet.css", "../../../images/./../images/goober/../spinner.gif"))
+ assert_equal("/images/spinner.gif", BundleFu.rewrite_relative_path("stylesheets/active_scaffold/default/./stylesheet.css", "../../../images/spinner.gif"))
+ assert_equal("/stylesheets/image.gif", BundleFu.rewrite_relative_path("stylesheets/main.css", "image.gif"))
+ assert_equal("/stylesheets/image.gif", BundleFu.rewrite_relative_path("/stylesheets////default/main.css", "..//image.gif"))
+ assert_equal("/images/image.gif", BundleFu.rewrite_relative_path("/stylesheets/default/main.css", "/images/image.gif"))
+ end
+
+ def test__bundle_css_file__should_rewrite_relatiave_path
+ bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_3.css"])
+# puts bundled_css
+ assert_match("background-image: url(/images/background.gif)", bundled_css)
+ assert_match("background-image: url(/images/groovy/background_2.gif)", bundled_css)
+ end
+end

0 comments on commit dd667f7

Please sign in to comment.