Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changed deprecated RAILS_ROOT to Rails.root. #1

Merged
merged 3 commits into from

3 participants

This page is out of date. Refresh to see the latest.
View
70 README.textile
@@ -1,35 +1,35 @@
-h1. Bundle fu
--------------
-
-Each css / js you load causes your site to load slower! You can speed things up
-exponentially by simply combining all your css/js files into one file each.
-
-Bundle_fu makes it easy to do. It's as easy as 1, 2!
-
-h2. USAGE / INSTALLATION
-------------------------
-
-h3. Step 1
-
-Install this plugin
-
-script/plugin install git://github.com/timcharper/bundle-fu.git
-
-h3. Step 2
-
-Put the following around your stylesheets/javascripts (note it works with any method of including assets!):
-
-<pre><code>
- <% bundle do %>
- ...
- <%= javascript_include_tag "prototype" %>
- <%= stylesheet_link_tag "basic.css" %>
- <%= calendar_date_select_includes params[:style] %>
- <script src="javascripts/application.js" type="text/javascript"></script>
- ...
- <% end %>
-</code></pre>
-
-That's it!
-
-"More info":http://code.google.com/p/bundle-fu/
+h1. Bundle fu
+-------------
+
+Each css / js you load causes your site to load slower! You can speed things up
+exponentially by simply combining all your css/js files into one file each.
+
+Bundle_fu makes it easy to do. It's as easy as 1, 2!
+
+h2. USAGE / INSTALLATION
+------------------------
+
+h3. Step 1
+
+Install this plugin
+
+script/plugin install git://github.com/timcharper/bundle-fu.git
+
+h3. Step 2
+
+Put the following around your stylesheets/javascripts (note it works with any method of including assets!):
+
+<pre><code>
+ <% bundle do %>
+ ...
+ <%= javascript_include_tag "prototype" %>
+ <%= stylesheet_link_tag "basic.css" %>
+ <%= calendar_date_select_includes params[:style] %>
+ <script src="javascripts/application.js" type="text/javascript"></script>
+ ...
+ <% end %>
+</code></pre>
+
+That's it!
+
+"More info":http://code.google.com/p/bundle-fu/
View
10 init.rb
@@ -1,6 +1,6 @@
-# EZ Bundle
-for file in ["/lib/bundle_fu.rb", "/lib/js_minimizer.rb", "/lib/bundle_fu/file_list.rb"]
-end
-require File.expand_path(File.join(File.dirname(__FILE__), "environment.rb"))
-
+# EZ Bundle
+for file in ["/lib/bundle_fu.rb", "/lib/js_minimizer.rb", "/lib/bundle_fu/file_list.rb"]
+end
+require File.expand_path(File.join(File.dirname(__FILE__), "environment.rb"))
+
ActionView::Base.send(:include, BundleFu::InstanceMethods)
View
268 lib/bundle_fu.rb
@@ -1,146 +1,146 @@
-class BundleFu
-
- class << self
- attr_accessor :content_store
- def init
- @content_store = {}
- end
-
- def bundle_files(filenames=[])
- output = ""
- filenames.each{ |filename|
- output << "/* --------- #{filename} --------- */ "
- output << "\n"
- begin
- content = (File.read(File.join(RAILS_ROOT, "public", filename)))
- rescue
- output << "/* FILE READ ERROR! */"
- next
- end
-
- output << (yield(filename, content)||"")
- }
- output
- end
-
- def bundle_js_files(filenames=[], options={})
- output =
- bundle_files(filenames) { |filename, content|
- if options[:compress]
- if Object.const_defined?("Packr")
- content
- else
- JSMinimizer.minimize_content(content)
- end
- else
- content
- end
- }
-
- if Object.const_defined?("Packr")
- # use Packr plugin (http://blog.jcoglan.com/packr/)
- Packr.new.pack(output, options[:packr_options] || {:shrink_vars => false, :base62 => false})
- else
- output
- end
-
- end
-
- def bundle_css_files(filenames=[], options = {})
- bundle_files(filenames) { |filename, content|
- BundleFu::CSSUrlRewriter.rewrite_urls(filename, content)
- }
- end
- end
-
- self.init
-
- module InstanceMethods
- # valid options:
- # :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"),
- :compress => true,
- :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)
- content_changed = false
-
- new_files = nil
- abs_filelist_paths = [:css, :js].inject({}) { | hash, filetype | hash[filetype] = File.join(RAILS_ROOT, "public", paths[filetype], "#{options[:name]}.#{filetype}.filelist"); hash }
-
- # only rescan file list if content_changed, or if a filelist cache file is missing
- unless content == BundleFu.content_store[options[:name]] && File.exists?(abs_filelist_paths[:css]) && File.exists?(abs_filelist_paths[:js])
- BundleFu.content_store[options[:name]] = content
- new_files = {:js => [], :css => []}
-
- content.scan(/(href|src) *= *["']([^"^'^\?]+)/i).each{ |property, value|
- case property
- when "src"
- new_files[:js] << value
- when "href"
- new_files[:css] << value
- end
- }
- end
-
- [:css, :js].each { |filetype|
- output_filename = File.join(paths[filetype], "#{options[:name]}.#{filetype}")
- abs_path = File.join(RAILS_ROOT, "public", output_filename)
- abs_filelist_path = abs_filelist_paths[filetype]
-
- 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 mtimes.
- new_filelist = new_files ? BundleFu::FileList.new(new_files[filetype]) : filelist.clone.update_mtimes
-
- unless new_filelist == filelist
- FileUtils.mkdir_p(File.join(RAILS_ROOT, "public", paths[filetype]))
- # 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
- # 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, options)
- File.open( abs_path, "w") {|f| f.puts output } if output
- end
- new_filelist.save_as(abs_filelist_path)
- end
-
+class BundleFu
+
+ class << self
+ attr_accessor :content_store
+ def init
+ @content_store = {}
+ end
+
+ def bundle_files(filenames=[])
+ output = ""
+ filenames.each{ |filename|
+ output << "/* --------- #{filename} --------- */ "
+ output << "\n"
+ begin
+ content = (File.read(File.join(Rails.root, "public", filename)))
+ rescue
+ output << "/* FILE READ ERROR! */"
+ next
+ end
+
+ output << (yield(filename, content)||"")
+ }
+ output
+ end
+
+ def bundle_js_files(filenames=[], options={})
+ output =
+ bundle_files(filenames) { |filename, content|
+ if options[:compress]
+ if Object.const_defined?("Packr")
+ content
+ else
+ JSMinimizer.minimize_content(content)
+ end
+ else
+ content
+ end
+ }
+
+ if Object.const_defined?("Packr")
+ # use Packr plugin (http://blog.jcoglan.com/packr/)
+ Packr.new.pack(output, options[:packr_options] || {:shrink_vars => false, :base62 => false})
+ else
+ output
+ end
+
+ end
+
+ def bundle_css_files(filenames=[], options = {})
+ bundle_files(filenames) { |filename, content|
+ BundleFu::CSSUrlRewriter.rewrite_urls(filename, content)
+ }
+ end
+ end
+
+ self.init
+
+ module InstanceMethods
+ # valid options:
+ # :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"),
+ :compress => true,
+ :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)
+ content_changed = false
+
+ new_files = nil
+ abs_filelist_paths = [:css, :js].inject({}) { | hash, filetype | hash[filetype] = File.join(Rails.root, "public", paths[filetype], "#{options[:name]}.#{filetype}.filelist"); hash }
+
+ # only rescan file list if content_changed, or if a filelist cache file is missing
+ unless content == BundleFu.content_store[options[:name]] && File.exists?(abs_filelist_paths[:css]) && File.exists?(abs_filelist_paths[:js])
+ BundleFu.content_store[options[:name]] = content
+ new_files = {:js => [], :css => []}
+
+ content.scan(/(href|src) *= *["']([^"^'^\?]+)/i).each{ |property, value|
+ case property
+ when "src"
+ new_files[:js] << value
+ when "href"
+ new_files[:css] << value
+ end
+ }
+ end
+
+ [:css, :js].each { |filetype|
+ output_filename = File.join(paths[filetype], "#{options[:name]}.#{filetype}")
+ abs_path = File.join(Rails.root, "public", output_filename)
+ abs_filelist_path = abs_filelist_paths[filetype]
+
+ 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 mtimes.
+ new_filelist = new_files ? BundleFu::FileList.new(new_files[filetype]) : filelist.clone.update_mtimes
+
+ unless new_filelist == filelist
+ FileUtils.mkdir_p(File.join(Rails.root, "public", paths[filetype]))
+ # 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
+ # 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, options)
+ 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) && options[:bundle_fu]
tag = filetype==:css ? stylesheet_link_tag(output_filename) : javascript_include_tag(output_filename)
- if Rails::version < "2.2.0"
+ if Rails::version < "2.2.0"
concat( tag , block.binding)
else
#concat doesn't need block.binding in Rails >= 2.2.0
concat( tag )
- end
-
- end
- }
-
+ end
+
+ end
+ }
+
unless options[:bundle_fu]
- if Rails::version < "2.2.0"
+ if Rails::version < "2.2.0"
concat( content, block.binding )
else
#concat doesn't need block.binding in Rails >= 2.2.0
concat( content )
- end
- end
- end
- end
+ end
+ end
+ end
+ end
end
View
128 lib/bundle_fu/file_list.rb
@@ -1,64 +1,64 @@
-require 'fileutils.rb'
-
-class BundleFu::FileList
- attr_accessor :filelist
-
- def initialize(filenames=[])
- self.filelist = []
-
- self.add_files(filenames)
- end
-
- def initialize_copy(from)
- self.filelist = from.filelist.collect{|entry| entry.clone}
- end
-
- def filenames
- self.filelist.collect{ |entry| entry[0] }
- end
-
- def update_mtimes
- old_filenames = self.filenames
- self.filelist = []
- # readding the files will effectively update the mtimes
- self.add_files(old_filenames)
- self
- end
-
- def self.open(filename)
- return nil unless File.exists?(filename)
- b = new
- File.open(filename, "rb") {|f|
- b.filelist = Marshal.load(f) # rescue [])
- }
- b
- rescue
- nil
- end
-
- # compares to see if one file list is exactly the same as another
- def ==(compare)
- return false if compare.nil?
- throw "cant compare with #{compare.class}" unless self.class===compare
-
- self.filelist == compare.filelist
- end
-
- def add_files(filenames=[])
- filenames.each{|filename|
- self.filelist << [ extract_filename_from_url(filename), (File.mtime(abs_location(filename)).to_i rescue 0) ]
- }
- end
-
- def extract_filename_from_url(url)
- url.gsub(/^https?:\/\/[^\/]+/i, '')
- end
-
- def save_as(filename)
- File.open(filename, "wb") {|f| f.puts Marshal.dump(self.filelist)}
- end
-protected
- def abs_location(filename)
- File.join(RAILS_ROOT, "public", filename)
- end
-end
+require 'fileutils.rb'
+
+class BundleFu::FileList
+ attr_accessor :filelist
+
+ def initialize(filenames=[])
+ self.filelist = []
+
+ self.add_files(filenames)
+ end
+
+ def initialize_copy(from)
+ self.filelist = from.filelist.collect{|entry| entry.clone}
+ end
+
+ def filenames
+ self.filelist.collect{ |entry| entry[0] }
+ end
+
+ def update_mtimes
+ old_filenames = self.filenames
+ self.filelist = []
+ # readding the files will effectively update the mtimes
+ self.add_files(old_filenames)
+ self
+ end
+
+ def self.open(filename)
+ return nil unless File.exists?(filename)
+ b = new
+ File.open(filename, "rb") {|f|
+ b.filelist = Marshal.load(f) # rescue [])
+ }
+ b
+ rescue
+ nil
+ end
+
+ # compares to see if one file list is exactly the same as another
+ def ==(compare)
+ return false if compare.nil?
+ throw "cant compare with #{compare.class}" unless self.class===compare
+
+ self.filelist == compare.filelist
+ end
+
+ def add_files(filenames=[])
+ filenames.each{|filename|
+ self.filelist << [ extract_filename_from_url(filename), (File.mtime(abs_location(filename)).to_i rescue 0) ]
+ }
+ end
+
+ def extract_filename_from_url(url)
+ url.gsub(/^https?:\/\/[^\/]+/i, '')
+ end
+
+ def save_as(filename)
+ File.open(filename, "wb") {|f| f.puts Marshal.dump(self.filelist)}
+ end
+protected
+ def abs_location(filename)
+ File.join(Rails.root, "public", filename)
+ end
+end
View
12 test/fixtures/public/stylesheets/css_3.css
@@ -1,7 +1,7 @@
-.relative_image_bg {
- background-image: url(../images/background.gif )
-}
-
-.relative_image_bg_2 {
- background-image: url( ../images/groovy/background_2.gif )
+.relative_image_bg {
+ background-image: url(../images/background.gif )
+}
+
+.relative_image_bg_2 {
+ background-image: url( ../images/groovy/background_2.gif )
}
View
110 test/functional/css_bundle_test.rb
@@ -1,55 +1,55 @@
-require File.join(File.dirname(__FILE__), '../test_helper.rb')
-
-class CSSBundleTest < Test::Unit::TestCase
- def test__rewrite_relative_path__should_rewrite
- assert_rewrites("/stylesheets/active_scaffold/default/stylesheet.css",
- "../../../images/spinner.gif" => "/images/spinner.gif",
- "../../../images/./../images/goober/../spinner.gif" => "/images/spinner.gif"
- )
-
- assert_rewrites("stylesheets/active_scaffold/default/./stylesheet.css",
- "../../../images/spinner.gif" => "/images/spinner.gif")
-
- assert_rewrites("stylesheets/main.css",
- "image.gif" => "/stylesheets/image.gif")
-
- assert_rewrites("/stylesheets////default/main.css",
- "..//image.gif" => "/stylesheets/image.gif")
-
- assert_rewrites("/stylesheets/default/main.css",
- "/images/image.gif" => "/images/image.gif")
- end
-
- def test__rewrite_relative_path__should_strip_spaces_and_quotes
- assert_rewrites("stylesheets/main.css",
- "'image.gif'" => "/stylesheets/image.gif",
- " image.gif " => "/stylesheets/image.gif"
- )
- end
-
- def test__rewrite_relative_path__shouldnt_rewrite_if_absolute_url
- assert_rewrites("stylesheets/main.css",
- " 'http://www.url.com/images/image.gif' " => "http://www.url.com/images/image.gif",
- "http://www.url.com/images/image.gif" => "http://www.url.com/images/image.gif",
- "ftp://www.url.com/images/image.gif" => "ftp://www.url.com/images/image.gif"
- )
- end
-
- def test__bundle_css_file__should_rewrite_relatiave_path
- bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_3.css"])
- assert_match("background-image: url(/images/background.gif)", bundled_css)
- assert_match("background-image: url(/images/groovy/background_2.gif)", bundled_css)
- end
-
- def test__bundle_css_files__no_images__should_return_content
- bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_1.css"])
- assert_match("css_1 { }", bundled_css)
- end
-
-
- def assert_rewrites(source_filename, rewrite_map)
- rewrite_map.each_pair{|source, dest|
- assert_equal(dest, BundleFu::CSSUrlRewriter.rewrite_relative_path(source_filename, source))
- }
- end
-end
+require File.join(File.dirname(__FILE__), '../test_helper.rb')
+
+class CSSBundleTest < Test::Unit::TestCase
+ def test__rewrite_relative_path__should_rewrite
+ assert_rewrites("/stylesheets/active_scaffold/default/stylesheet.css",
+ "../../../images/spinner.gif" => "/images/spinner.gif",
+ "../../../images/./../images/goober/../spinner.gif" => "/images/spinner.gif"
+ )
+
+ assert_rewrites("stylesheets/active_scaffold/default/./stylesheet.css",
+ "../../../images/spinner.gif" => "/images/spinner.gif")
+
+ assert_rewrites("stylesheets/main.css",
+ "image.gif" => "/stylesheets/image.gif")
+
+ assert_rewrites("/stylesheets////default/main.css",
+ "..//image.gif" => "/stylesheets/image.gif")
+
+ assert_rewrites("/stylesheets/default/main.css",
+ "/images/image.gif" => "/images/image.gif")
+ end
+
+ def test__rewrite_relative_path__should_strip_spaces_and_quotes
+ assert_rewrites("stylesheets/main.css",
+ "'image.gif'" => "/stylesheets/image.gif",
+ " image.gif " => "/stylesheets/image.gif"
+ )
+ end
+
+ def test__rewrite_relative_path__shouldnt_rewrite_if_absolute_url
+ assert_rewrites("stylesheets/main.css",
+ " 'http://www.url.com/images/image.gif' " => "http://www.url.com/images/image.gif",
+ "http://www.url.com/images/image.gif" => "http://www.url.com/images/image.gif",
+ "ftp://www.url.com/images/image.gif" => "ftp://www.url.com/images/image.gif"
+ )
+ end
+
+ def test__bundle_css_file__should_rewrite_relatiave_path
+ bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_3.css"])
+ assert_match("background-image: url(/images/background.gif)", bundled_css)
+ assert_match("background-image: url(/images/groovy/background_2.gif)", bundled_css)
+ end
+
+ def test__bundle_css_files__no_images__should_return_content
+ bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_1.css"])
+ assert_match("css_1 { }", bundled_css)
+ end
+
+
+ def assert_rewrites(source_filename, rewrite_map)
+ rewrite_map.each_pair{|source, dest|
+ assert_equal(dest, BundleFu::CSSUrlRewriter.rewrite_relative_path(source_filename, source))
+ }
+ end
+end
View
90 test/functional/file_list_test.rb
@@ -1,46 +1,46 @@
-require File.join(File.dirname(__FILE__), '../test_helper.rb')
-
-require "test/unit"
-
-# require "library_file_name"
-
-class FileListTest < Test::Unit::TestCase
- def setup
-
- end
-
- def test__new_files__should_get_mtimes
- filename = "/javascripts/js_1.js"
- filelist = BundleFu::FileList.new([filename])
-
- assert_equal(File.mtime(File.join(RAILS_ROOT, "public", filename)).to_i,filelist.filelist[0][1])
- end
-
- def test__serialization
- filelist_filename = File.join(RAILS_ROOT, "public", "temp")
- filelist = BundleFu::FileList.new("/javascripts/js_1.js")
-
- filelist.save_as(filelist_filename)
- filelist2 = BundleFu::FileList.open(filelist_filename)
-
- assert(filelist == filelist2, "expected to be same, but differed.\n#{filelist.to_yaml}\n\n#{filelist2.to_yaml}")
- ensure
- FileUtils.rm_f(filelist_filename)
- end
-
- 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_mtime__shouldnt_equate
- filename1 = "/javascripts/js_1.js"
- filename2 = "/javascripts/js_2.js"
- assert BundleFu::FileList.new(filename1) != BundleFu::FileList.new(filename2)
- end
-
- def test__clone_item
- b = BundleFu::FileList.new("/javascripts/js_1.js")
- assert b == b.clone
- end
+require File.join(File.dirname(__FILE__), '../test_helper.rb')
+
+require "test/unit"
+
+# require "library_file_name"
+
+class FileListTest < Test::Unit::TestCase
+ def setup
+
+ end
+
+ def test__new_files__should_get_mtimes
+ filename = "/javascripts/js_1.js"
+ filelist = BundleFu::FileList.new([filename])
+
+ assert_equal(File.mtime(File.join(Rails.root, "public", filename)).to_i,filelist.filelist[0][1])
+ end
+
+ def test__serialization
+ filelist_filename = File.join(Rails.root, "public", "temp")
+ filelist = BundleFu::FileList.new("/javascripts/js_1.js")
+
+ filelist.save_as(filelist_filename)
+ filelist2 = BundleFu::FileList.open(filelist_filename)
+
+ assert(filelist == filelist2, "expected to be same, but differed.\n#{filelist.to_yaml}\n\n#{filelist2.to_yaml}")
+ ensure
+ FileUtils.rm_f(filelist_filename)
+ end
+
+ 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_mtime__shouldnt_equate
+ filename1 = "/javascripts/js_1.js"
+ filename2 = "/javascripts/js_2.js"
+ assert BundleFu::FileList.new(filename1) != BundleFu::FileList.new(filename2)
+ end
+
+ def test__clone_item
+ b = BundleFu::FileList.new("/javascripts/js_1.js")
+ assert b == b.clone
+ end
end
View
60 test/mock_view.rb
@@ -1,31 +1,31 @@
-class MockView
- # set RAILS_ROOT to fixtures dir so we use those files
- include BundleFu::InstanceMethods
- ::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)
- yield
- end
-
- def concat(output, *args)
- @output << output
- end
-
- def stylesheet_link_tag(*args)
- 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.mtime(File.join(RAILS_ROOT, 'public', arg)).to_i}\" type=\"text/javascript\"></script>" } * "\n"
- end
-
+class MockView
+ # set Rails.root to fixtures dir so we use those files
+ include BundleFu::InstanceMethods
+ ::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)
+ yield
+ end
+
+ def concat(output, *args)
+ @output << output
+ end
+
+ def stylesheet_link_tag(*args)
+ 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.mtime(File.join(Rails.root, 'public', arg)).to_i}\" type=\"text/javascript\"></script>" } * "\n"
+ end
+
end
View
74 test/test_helper.rb
@@ -1,38 +1,38 @@
-require 'test/unit'
-require "rubygems"
-require 'active_support'
-
-for file in ["../environment.rb", "mock_view.rb"]
- require File.expand_path(File.join(File.dirname(__FILE__), file))
-end
-
-def dbg
- require 'ruby-debug'
- Debugger.start
- debugger
-end
-
-class Object
- def to_regexp
- is_a?(Regexp) ? self : Regexp.new(Regexp.escape(self.to_s))
- end
-end
-
-class Test::Unit::TestCase
- @@content_include_some = <<-EOF
- <script src="/javascripts/js_1.js?1000" type="text/javascript"></script>
- <script src="/javascripts/js_2.js?1000" type="text/javascript"></script>
- <link href="/stylesheets/css_1.css?1000" media="screen" rel="Stylesheet" type="text/css" />
- <link href="/stylesheets/css_2.css?1000" media="screen" rel="Stylesheet" type="text/css" />
- EOF
-
- # the same content, slightly changed
- @@content_include_all = @@content_include_some + <<-EOF
- <script src="/javascripts/js_3.js?1000" type="text/javascript"></script>
- <link href="/stylesheets/css_3.css?1000" media="screen" rel="Stylesheet" type="text/css" />
- EOF
-
- def public_file(filename)
- File.join(::RAILS_ROOT, "public", filename)
- end
+require 'test/unit'
+require "rubygems"
+require 'active_support'
+
+for file in ["../environment.rb", "mock_view.rb"]
+ require File.expand_path(File.join(File.dirname(__FILE__), file))
+end
+
+def dbg
+ require 'ruby-debug'
+ Debugger.start
+ debugger
+end
+
+class Object
+ def to_regexp
+ is_a?(Regexp) ? self : Regexp.new(Regexp.escape(self.to_s))
+ end
+end
+
+class Test::Unit::TestCase
+ @@content_include_some = <<-EOF
+ <script src="/javascripts/js_1.js?1000" type="text/javascript"></script>
+ <script src="/javascripts/js_2.js?1000" type="text/javascript"></script>
+ <link href="/stylesheets/css_1.css?1000" media="screen" rel="Stylesheet" type="text/css" />
+ <link href="/stylesheets/css_2.css?1000" media="screen" rel="Stylesheet" type="text/css" />
+ EOF
+
+ # the same content, slightly changed
+ @@content_include_all = @@content_include_some + <<-EOF
+ <script src="/javascripts/js_3.js?1000" type="text/javascript"></script>
+ <link href="/stylesheets/css_3.css?1000" media="screen" rel="Stylesheet" type="text/css" />
+ EOF
+
+ def public_file(filename)
+ File.join(::Rails.root, "public", filename)
+ end
end
Something went wrong with that request. Please try again.