Skip to content
Browse files

bypass parameter

git-svn-id: http://bundle-fu.googlecode.com/svn/trunk@5 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information...
1 parent 21c5016 commit b2e2b01dff534dce7ed5cf6282cedc5438f8c7a4 timcharper committed Aug 11, 2007
Showing with 29 additions and 17 deletions.
  1. +10 −6 lib/bundle_fu.rb
  2. +3 −3 lib/bundle_fu/file_list.rb
  3. +10 −2 test/functional/bundle_fu_test.rb
  4. +4 −4 test/functional/file_list_test.rb
  5. +2 −2 test/mock_view.rb
View
16 lib/bundle_fu.rb
@@ -30,7 +30,8 @@ def bundle(options={}, &block)
options = {
:css_path => "/stylesheets",
:js_path => "/javascripts",
- :name => "bundle"
+ :name => "bundle",
+ :bypass => false
}.merge(options)
paths = { :css => options[:css_path], :js => options[:js_path] }
@@ -65,26 +66,29 @@ def bundle(options={}, &block)
filelist = FileList.open( abs_filelist_path )
- # check against newly parsed filelist. If we didn't parse the filelist from the output, then check against the updated ctimes.
- new_filelist = new_files ? BundleFu::FileList.new(new_files[filetype]) : filelist.clone.update_ctimes
+ # check against newly parsed filelist. If we didn't parse the filelist from the output, then check against the updated mtimes.
+ new_filelist = new_files ? BundleFu::FileList.new(new_files[filetype]) : filelist.clone.update_mtimes
unless new_filelist == filelist
# regenerate everything
if new_filelist.filenames.empty?
# delete the javascript/css bundle file if it's empty, but keep the filelist cache
FileUtils.rm_f(abs_path)
else
- content = BundleFu.bundle_files(new_filelist.filenames)
- File.open( abs_path, "w") {|f| f.puts content } if content
+ output = BundleFu.bundle_files(new_filelist.filenames)
+ File.open( abs_path, "w") {|f| f.puts output } if output
end
new_filelist.save_as(abs_filelist_path)
end
- if File.exists?(abs_path)
+ if File.exists?(abs_path) && !options[:bypass]
concat( filetype==:css ? stylesheet_link_tag(path) : javascript_include_tag(path), block.binding)
end
}
+ if options[:bypass]
+ concat( content, block.binding )
+ end
end
end
end
View
6 lib/bundle_fu/file_list.rb
@@ -17,10 +17,10 @@ def filenames
self.filelist.collect{ |entry| entry[0] }
end
- def update_ctimes
+ def update_mtimes
old_filenames = self.filenames
self.filelist = []
- # readding the files will effectively update the ctimes
+ # readding the files will effectively update the mtimes
self.add_files(old_filenames)
self
end
@@ -42,7 +42,7 @@ def ==(compare)
def add_files(filenames=[])
filenames.each{|filename|
- self.filelist << [ filename, (File.ctime(abs_location(filename)).to_i rescue 0) ]
+ self.filelist << [ filename, (File.mtime(abs_location(filename)).to_i rescue 0) ]
}
end
View
12 test/functional/bundle_fu_test.rb
@@ -108,13 +108,13 @@ def test__bundle__css_only__should_output_css_include_statement
end
- def test__nonexisting_file__should_use_blank_file_created_at_0_ctime
+ def test__nonexisting_file__should_use_blank_file_created_at_0_mtime
@mock_view.bundle { %q{<script src="/javascripts/non_existing_file.js?1000" type="text/javascript"></script>} }
assert_public_files_match(cache_files("bundle").grep(/javascripts/), "FILE READ ERROR")
filelist = BundleFu::FileList.open(public_file("/javascripts/bundle.js.filelist"))
- assert_equal(0, filelist.filelist[0][1], "ctime for first file should be 0")
+ assert_equal(0, filelist.filelist[0][1], "mtime for first file should be 0")
end
def test__missing_cache_filelist__should_regenerate
@@ -126,6 +126,14 @@ def test__missing_cache_filelist__should_regenerate
@mock_view.bundle { @@content_include_some }
assert_public_files_no_match(cache_files("bundle"), "BOGUS", "Should have regenerated the file, but it didn't")
end
+
+ def test__bypass__should_generate_files_but_render_normal_output
+ @mock_view.bundle(:bypass => true) { @@content_include_some }
+ assert_public_file_exists("/stylesheets/bundle.css")
+ assert_public_file_exists("/stylesheets/bundle.css.filelist")
+
+ assert_equal(@@content_include_some, @mock_view.output)
+ end
private
def public_file(filename)
File.join(::RAILS_ROOT, "public", filename)
View
8 test/functional/file_list_test.rb
@@ -9,11 +9,11 @@ def setup
end
- def test__new_files__should_get_ctimes
+ def test__new_files__should_get_mtimes
filename = "/javascripts/js_1.js"
filelist = BundleFu::FileList.new([filename])
- assert_equal(File.ctime(File.join(RAILS_ROOT, "public", filename)).to_i,filelist.filelist[0][1])
+ assert_equal(File.mtime(File.join(RAILS_ROOT, "public", filename)).to_i,filelist.filelist[0][1])
end
def test__serialization
@@ -28,12 +28,12 @@ def test__serialization
FileUtils.rm_f(filelist_filename)
end
- def test__equality__same_file_and_ctime__should_equate
+ def test__equality__same_file_and_mtime__should_equate
filename = "/javascripts/js_1.js"
assert BundleFu::FileList.new(filename) == BundleFu::FileList.new(filename)
end
- def test__equality__dif_file_and_ctime__shouldnt_equate
+ def test__equality__dif_file_and_mtime__shouldnt_equate
filename1 = "/javascripts/js_1.js"
filename2 = "/javascripts/js_2.js"
assert BundleFu::FileList.new(filename1) != BundleFu::FileList.new(filename2)
View
4 test/mock_view.rb
@@ -18,10 +18,10 @@ def concat(output, *args)
end
def stylesheet_link_tag(*args)
- args.collect{|arg| "<link href=\"#{arg}?#{File.ctime(File.join(RAILS_ROOT, 'public', arg)).to_i}\" media=\"screen\" rel=\"Stylesheet\" type=\"text/css\" />" } * "\n"
+ args.collect{|arg| "<link href=\"#{arg}?#{File.mtime(File.join(RAILS_ROOT, 'public', arg)).to_i}\" media=\"screen\" rel=\"Stylesheet\" type=\"text/css\" />" } * "\n"
end
def javascript_include_tag(*args)
- args.collect{|arg| "<script src=\"#{arg}?#{File.ctime(File.join(RAILS_ROOT, 'public', arg)).to_i}\" type=\"text/javascript\"></script>" } * "\n"
+ 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 b2e2b01

Please sign in to comment.
Something went wrong with that request. Please try again.