module Xmvc class BuilderManager class << self def dispatch(name, *params) name = name.to_sym options = params.shift || {} case name when :setup setup(options) else begin @jammit = jammit(options) @jammit.invoke(:build, [name]) rescue Jammit::Error => e raise Xmvc::BuilderError.new(e.message) end end end private def setup(options) begin ## # Invoke jammit init app-name so that Jammit creates it's config/assets.yml # Note that we must pass-in the name of the newly created app @name so that # Jammit appends that to its config_path, otherwise it would create its config file # in the pwd. @asset_root = options[:asset_root] || File.expand_path('.') javascripts = { "application" => application_assets("javascripts", options[:application]) } options[:vendors].each do |vendor| javascripts.update(vendor["name"] => vendor_assets("javascripts", vendor)) end jammit = Jammit::CLI.new([], options) jammit.invoke(:init) jammit.invoke(:config, ["set", "javascripts", javascripts]) jammit.invoke(:build) rescue Jammit::Error => e raise Xmvc::BuilderError.new(e.message) end end def vendor_assets(type, vendor) vendor[type].map {|f| File.join("vendor", vendor["name"], f) } end def application_assets(type, assets) assets.map {|f| File.join(f)} end def jammit(options={}) Jammit::CLI.new([], options) end end end end