Class: Html2haml::Exec::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/html2haml/exec.rb

Overview

An abstract class that encapsulates the executable code for the Html2haml executable. It's split into a base class and a subclass for historic reasons: this previously was used by all the executables in the Haml project, before Html2haml was moved into its own gem.

Direct Known Subclasses

HTML2Haml

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Generic

Returns a new instance of Generic.

Parameters:

  • args (Array<String>)

    The command-line arguments


14
15
16
17
# File 'lib/html2haml/exec.rb', line 14

def initialize(args)
  @args = args
  @options = {:for_engine => {}}
end

Instance Method Details

#parseObject

Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program.

See Also:


41
42
43
44
45
46
47
48
# File 'lib/html2haml/exec.rb', line 41

def parse
  @opts = OptionParser.new(&method(:set_opts))
  @opts.parse!(@args)

  process_result

  @options
end

#parse!Object

Parses the command-line arguments and runs the executable. Calls Kernel#exit at the end, so it never returns.

See Also:


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/html2haml/exec.rb', line 23

def parse!
  begin
    parse
  rescue Exception => e
    raise e if @options[:trace] || e.is_a?(SystemExit)

    $stderr.print "#{e.class}: " unless e.class == RuntimeError
    $stderr.puts "#{e.message}"
    $stderr.puts "  Use --trace for backtrace."
    exit 1
  end
  exit 0
end

#to_sString

Returns A description of the executable.

Returns:

  • (String)

    A description of the executable


51
52
53
# File 'lib/html2haml/exec.rb', line 51

def to_s
  @opts.to_s
end