Skip to content

Instantly share code, notes, and snippets.

@shingara
Forked from rhyhann/gist:153646
Created July 23, 2009 22:20
Show Gist options
  • Save shingara/153682 to your computer and use it in GitHub Desktop.
Save shingara/153682 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
%w[rubygems sinatra jsmin cssmin].each{|l| require l}
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
# Now, we read each file and concatenate it in an array
bundle = files.map { |f| options.public + "/#{f}.#{format}"} \
.map { |f| options.send("#{format}_proc",f) }.join("\n")
# If it does not exist
FileUtils.mkdir_p(File.dirname(file)
File.open(file, 'a+').write(bundle)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment