Skip to content

Instantly share code, notes, and snippets.

@defunkt
Forked from jbarnette/bundle.rake
Created August 26, 2009 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save defunkt/175814 to your computer and use it in GitHub Desktop.
Save defunkt/175814 to your computer and use it in GitHub Desktop.
RAILS_ROOT ||= ENV["RAILS_ROOT"]
namespace :bundle do
js_bundle = Rails.root + "/public/javascripts/bundle.js"
js_files = Dir[Rails.root + "/public/javascripts/{github,jquery}.*.js"].sort
task :all => [ js_bundle, :gist_js, :css ]
file js_bundle => js_files do |task|
require 'lib/js_minimizer'
File.open(task.name, 'w+') do |f|
f.puts JSMinimizer.minimize_files(task.prerequisites)
end
puts "=> bundled js at #{task.name}"
end
task :gist_js do
require 'lib/js_minimizer'
paths = []
paths += Dir[RAILS_ROOT + '/public/javascripts/gist/*.js'].sort
paths = paths.flatten
target = RAILS_ROOT + '/public/javascripts/gist.js'
File.open(target, 'w+') do |f|
f.puts JSMinimizer.minimize_files(*paths)
end
puts "=> bundled gist js at #{target}"
end
task :css do
paths = []
paths += Dir[RAILS_ROOT + '/public/stylesheets/*.css'].reject { |path| path =~ /bundle|admin|staff|scaffold|iui/ }.sort
bundle = ''
paths.flatten.each do |path|
bundle << File.read(path) << "\n"
end
rawpath = "/tmp/bundle_raw.css"
minpath = "/tmp/bundle_min.css"
bundlepath = RAILS_ROOT + "/public/stylesheets/bundle.css"
yuipath = RAILS_ROOT + '/lib/yuicompressor-2.4.1.jar'
File.open(rawpath, 'w') { |f| f.write(bundle) }
`java -jar #{yuipath} --line-break 0 #{rawpath} -o #{bundlepath}`
puts "=> bundled css at #{bundlepath}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment