Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pushed new branch: 0_2_0

git-svn-id: http://bundle-fu.googlecode.com/svn/tags/RELEASE_0_2_0@25 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information...
commit 7de42f17bd402465b16671862c42d6c693e04f8b 2 parents 3d3a2df + 4b0b0c2
timcharper authored
View
9 lib/bundle_fu.rb
@@ -27,11 +27,14 @@ module InstanceMethods
# :name - The name of the css and js files you wish to output
# returns true if a regen occured. False if not.
def bundle(options={}, &block)
+ # allow bypassing via the querystring
+ session[:bundle_fu] = (params[:bundle_fu]=="true") if params.has_key?(:bundle_fu)
+
options = {
:css_path => ($bundle_css_path || "/stylesheets/cache"),
:js_path => ($bundle_js_path || "/javascripts/cache"),
:name => ($bundle_default_name || "bundle"),
- :bypass => ($bundle_bypass || false)
+ :bundle_fu => ( session[:bundle_fu].nil? ? ($bundle_fu.nil? ? false : true) : session[:bundle_fu] )
}.merge(options)
paths = { :css => options[:css_path], :js => options[:js_path] }
@@ -80,12 +83,12 @@ def bundle(options={}, &block)
new_filelist.save_as(abs_filelist_path)
end
- if File.exists?(abs_path) && !options[:bypass]
+ if File.exists?(abs_path) && options[:bundle_fu]
concat( filetype==:css ? stylesheet_link_tag(path) : javascript_include_tag(path), block.binding)
end
}
- if options[:bypass]
+ unless options[:bundle_fu]
concat( content, block.binding )
end
end
View
2  lib/bundle_fu/file_list.rb
@@ -32,6 +32,8 @@ def self.open(filename)
b.filelist = Marshal.load(f) # rescue [])
}
b
+ rescue
+ nil
end
# compares to see if one file list is exactly the same as another
View
13 test/functional/bundle_fu_test.rb
@@ -50,7 +50,6 @@ def test__content_changes__should_refresh_cache
assert_public_files_match(cache_files("bundle"), "BOGUS")
# now, pass in some new content. Make sure that the css/js files are regenerated
-# dbg
@mock_view.bundle { @@content_include_all }
assert_public_files_no_match(cache_files("bundle"), "BOGUS")
assert_public_files_no_match(cache_files("bundle"), "BOGUS")
@@ -61,7 +60,6 @@ def test__modified_time_differs_from_file__should_refresh_cache
# we're gonna hack each of them and set all the modified times to 0
cache_files("bundle").each{|filename|
abs_filelist_path = public_file(filename + ".filelist")
-# dbg
b = BundleFu::FileList.open(abs_filelist_path)
b.filelist.each{|entry| entry[1] = entry[1] - 100 }
b.save_as(abs_filelist_path)
@@ -134,6 +132,17 @@ def test__bypass__should_generate_files_but_render_normal_output
assert_equal(@@content_include_some, @mock_view.output)
end
+
+ def test__bypass_param_set__should_honor_and_store_in_session
+ @mock_view.params[:bundle_bypass] = "true"
+ @mock_view.bundle { @@content_include_some }
+ assert_equal(@@content_include_some, @mock_view.output)
+
+ @mock_view.params.delete(:bundle_bypass)
+ @mock_view.bundle { @@content_include_some }
+ assert_equal(@@content_include_some*2, @mock_view.output)
+ end
+
private
def public_file(filename)
File.join(::RAILS_ROOT, "public", filename)
View
6 test/mock_view.rb
@@ -4,9 +4,12 @@ class MockView
::RAILS_ROOT = File.join(File.dirname(__FILE__), 'fixtures')
attr_accessor :output
-
+ attr_accessor :session
+ attr_accessor :params
def initialize
@output = ""
+ @session = {}
+ @params = {}
end
def capture(&block)
@@ -24,4 +27,5 @@ def stylesheet_link_tag(*args)
def javascript_include_tag(*args)
args.collect{|arg| "<script src=\"#{arg}?#{File.mtime(File.join(RAILS_ROOT, 'public', arg)).to_i}\" type=\"text/javascript\"></script>" } * "\n"
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.