class AssetPacker::CLI

Constants

EXIT_FAILURE
EXIT_SUCCESS

Attributes

infile[R]
outfile[R]

Public Class Methods

create_from_args(argv) click to toggle source
# File lib/asset_packer/cli.rb, line 37
def self.create_from_args(argv)
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: asset_packer [options] input_file.html output_file.html"
    opts.on('--version', 'Print asset_packers version') do |name|
      raise ExitEarly, "asset_packer-#{AssetPacker::VERSION}"
    end.on('--help', 'Display help on command line usage') do
      raise ExitEarly, opts
    end
  end

  opts.parse!(argv)

  if argv.length != 2
    raise ExitEarly.new(opts, EXIT_FAILURE)
  end

  new(*argv)
end
new(infile, outfile) click to toggle source
# File lib/asset_packer/cli.rb, line 21
def initialize(infile, outfile)
  @infile  = infile
  @outfile = Pathname(outfile).expand_path
end
run(argv) click to toggle source
# File lib/asset_packer/cli.rb, line 26
def self.run(argv)
  create_from_args(argv).run
  EXIT_SUCCESS
rescue ExitEarly => exception
  $stderr.puts(exception)
  exception.exit_code
rescue => exception
  $stderr.puts(exception)
  EXIT_FAILURE
end

Public Instance Methods

run() click to toggle source
# File lib/asset_packer/cli.rb, line 56
def run
  asset_dir = outfile.dirname.join("#{outfile.basename(outfile.extname)}_assets")
  local = Processor::Local.new(infile, asset_dir, outfile)
  doc = Hexp.parse(local.retrieve_asset(infile))
  File.write(outfile, local.(doc).to_html)
end