#!/usr/bin/env ruby
# Copyright (c) 2008 Blake Elshire, Chris Griego
#
# Blender is freely distributable under the terms of an MIT-style license.
# For details, see http://www.opensource.org/licenses/mit-license.php
$:.unshift File.join(File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__), *%w[.. lib])
require 'optparse'
require 'front_end_architect/blender'
options = {}
def section(opts, title)
opts.separator ''
opts.separator title + ':'
end
opts = OptionParser.new do |opts|
version = "Front-End Blender v#{FrontEndArchitect::Blender::VERSION}"
opts.on('-g', '--generate', String, "Generate a stub Blendfile") { options[:generate] = true }
opts.on('-f FILE', '--file FILE', String, "Use specified Blendfile") {|f| options[:blendfile] = f }
opts.on('-r ROOT', '--root ROOT', String, "Specify the path to the web root directory") {|r| options[:root] = r }
opts.on('-t TYPE', '--type TYPE', [:css, :js], "Select file type to blend (css, js)") {|t| options[:file_type] = t }
opts.on('-m [MINIFIER]', '--min [MINIFIER]', [:yui, :none], "Select minifier to use (yui, none)") {|m| options[:min] = m.nil? ? :none : m.to_sym }
opts.on('-c [BUSTER]', '--cache-buster [BUSTER]', String, "Add cache busters to URLs in CSS") {|b| options[:cache_buster] = b.nil? ? :mtime : b }
opts.on( '--force', String, "Don't allow output files to be skipped") { options[:force] = true }
opts.on( '--yui=YUIOPTS', String, "Pass arguments to YUI Compressor") {|o| options[:yuiopts] = o }
section opts, 'Experimental'
opts.on('-d', '--data', String, "Convert url(file.ext) to url(data:) in CSS") { options[:data] = true }
opts.on('-z', '--gzip', String, "Additionally generate gzipped output files") { options[:gzip] = true }
section opts, 'Meta'
opts.on('-h', '--help', "Show this message") { puts opts; exit 0 }
opts.on('-V', '--version', "Show the version number") { puts version; exit 0 }
opts.parse!(ARGV) rescue return false
end
begin
blender = FrontEndArchitect::Blender.new(options)
if (options[:generate])
blender.generate
else
blender.blend
end
rescue Exception => e
puts e
exit 1
end