Skip to content

Commit

Permalink
pushed new branch: 0_2_0
Browse files Browse the repository at this point in the history
git-svn-id: http://bundle-fu.googlecode.com/svn/tags/RELEASE_0_2_0@25 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information
timcharper committed Aug 15, 2007
2 parents 3d3a2df + 4b0b0c2 commit 7de42f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/bundle_fu.rb
Expand Up @@ -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] }
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/bundle_fu/file_list.rb
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions test/functional/bundle_fu_test.rb
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/mock_view.rb
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 7de42f1

Please sign in to comment.