Skip to content

Instantly share code, notes, and snippets.

@rhyhann
Created July 23, 2009 21:43
Show Gist options
  • Save rhyhann/153646 to your computer and use it in GitHub Desktop.
Save rhyhann/153646 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
%w[rubygems sinatra jsmin cssmin].each{|l| require l}
configure do
set :bundle, 'bundle'
end
configure :development do
set :js_proc, proc {|f| "\n/* '#{f}' */\n" + File.read(f)}
set :css_proc, proc {|f| "\n/* '#{f}' */\n" +File.read(f)}
end
configure :production do
set :js_proc,
proc{|f|"/* '#{File.basename(f)}' */\n" + JSMin.minify(File.read(f))}
set :css_proc,
proc{|f| "/* '#{File.basename(f)}' */\n"+ CSSMin.minify(File.read(f))}
end
def bundle(name, *files)
# All the needed variables
format = name.sub!(/.*\.(.*)$/, $1)
file = "#{options.public}/#{options.bundle}/#{files.join(',')}.#{format}"
# Now, we read each file and concatenate it in an array
files.map! { |f| options.public + "/#{f}.#{format}"} \
.map! { |f| options.send("#{format}_proc",f) }.join("\n")
# If it does not exist
dir = File.dirname(file)
FileUtils.mkdir_p(dir) unless File.exists?(dir)
File.open(file, 'w+').write(files)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment