Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed the override paramter

git-svn-id: http://bundle-fu.googlecode.com/svn/trunk@26 1db77ec0-6337-0410-9320-454da9aca44f
  • Loading branch information...
commit 27a781ae30425cebd3b83f225bd4674a91d2788a 1 parent 1e586cb
timcharper authored
Showing with 39 additions and 16 deletions.
  1. +39 −16 lib/bundle_fu.rb
View
55 lib/bundle_fu.rb
@@ -6,15 +6,37 @@ def init
@content_store = {}
end
- def bundle_files(filenames=[])
- return nil if filenames.empty?
-
- output = ""
- filenames.each{|filename|
- output << "/* -------------- #{filename} ------------- */ "
+ def each_read_file(filenames=[])
+ filenames.each{ |filename|
+ output = "/* -------------- #{filename} ------------- */ "
output << "\n"
- output << (File.read(File.join(RAILS_ROOT, "public", filename)) rescue "/* FILE READ ERROR! */")
+ output << (File.read(File.join(RAILS_ROOT, "public", filename)) rescue ( return "/* FILE READ ERROR! */"))
output << "\n"
+ yield filename, output
+ }
+ end
+
+ def bundle_js_files(filenames=[], output_filename = "", options={})
+ output = ""
+ each_read_file(filenames) { |filename, content|
+ }
+ end
+
+ def rewrite_relative_path(old_filename, new_filename)
+
+ end
+
+ def bundle_css_files(filenames=[], output_filename = "", options = {})
+ output = ""
+ each_read_file(filenames) { |filename, content|
+ # rewrite the URL reference paths
+ # url(../../../images/active_scaffold/default/add.gif);
+ # url(/stylesheets/active_scaffold/default/../../../images/active_scaffold/default/add.gif);
+ # url(/stylesheets/active_scaffold/../../images/active_scaffold/default/add.gif);
+ # url(/stylesheets/../images/active_scaffold/default/add.gif);
+ # url(/images/active_scaffold/default/add.gif);
+
+ output << self.send("sanitized_#{options[:type]}", options)
}
output
end
@@ -34,7 +56,7 @@ def bundle(options={}, &block)
:css_path => ($bundle_css_path || "/stylesheets/cache"),
:js_path => ($bundle_js_path || "/javascripts/cache"),
:name => ($bundle_default_name || "bundle"),
- :bundle_fu => ( session[:bundle_fu].nil? ? ($bundle_fu.nil? ? false : true) : session[:bundle_fu] )
+ :bundle_fu => ( session[:bundle_fu].nil? ? ($bundle_fu.nil? ? true : $bundle_fu) : session[:bundle_fu] )
}.merge(options)
paths = { :css => options[:css_path], :js => options[:js_path] }
@@ -53,18 +75,18 @@ def bundle(options={}, &block)
content.scan(/(href|src) *= *["']([^"^'^\?]+)/i).each{ |property, value|
case property
when "src"
- new_files[:js] << value
+ js_files[:js] << value
when "href"
- new_files[:css] << value
+ css_files[:css] << value
end
}
end
[:css, :js].each { |filetype|
- path = File.join(paths[filetype], "#{options[:name]}.#{filetype}")
- abs_path = File.join(RAILS_ROOT, "public", path)
+ 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.
@@ -77,14 +99,15 @@ 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
- output = BundleFu.bundle_files(new_filelist.filenames)
- File.open( abs_path, "w") {|f| f.puts output } if output
+ 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
end
new_filelist.save_as(abs_filelist_path)
end
if File.exists?(abs_path) && options[:bundle_fu]
- concat( filetype==:css ? stylesheet_link_tag(path) : javascript_include_tag(path), block.binding)
+ concat( filetype==:css ? stylesheet_link_tag(output_filename) : javascript_include_tag(output_filename), block.binding)
end
}
Please sign in to comment.
Something went wrong with that request. Please try again.