jbarnette (owner)

Fork Of

Forks

Revisions

gist: 175801 Download_button fork
public
Public Clone URL: git://gist.github.com/175801.git
Embed All Files: show embed
bundle.rake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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