Class: AssetPacker::CLI
- Inherits:
-
Object
- Object
- AssetPacker::CLI
- Defined in:
- lib/asset_packer/cli.rb
Defined Under Namespace
Classes: ExitEarly
Constant Summary collapse
- EXIT_SUCCESS =
0
- EXIT_FAILURE =
1
Instance Attribute Summary collapse
-
#infile ⇒ Object
readonly
Returns the value of attribute infile.
-
#outfile ⇒ Object
readonly
Returns the value of attribute outfile.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(infile, outfile) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(infile, outfile) ⇒ CLI
Returns a new instance of CLI.
21 22 23 24 |
# File 'lib/asset_packer/cli.rb', line 21 def initialize(infile, outfile) @infile = infile @outfile = Pathname(outfile). end |
Instance Attribute Details
#infile ⇒ Object (readonly)
Returns the value of attribute infile.
19 20 21 |
# File 'lib/asset_packer/cli.rb', line 19 def infile @infile end |
#outfile ⇒ Object (readonly)
Returns the value of attribute outfile.
19 20 21 |
# File 'lib/asset_packer/cli.rb', line 19 def outfile @outfile end |
Class Method Details
.create_from_args(argv) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/asset_packer/cli.rb', line 37 def self.create_from_args(argv) opts = OptionParser.new do |opts| opts. = "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 |
.run(argv) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#run ⇒ Object
56 57 58 59 60 61 |
# 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 |