Class Haml::Exec::HTML2Haml
In: lib/haml/exec.rb
Parent: Generic

The `html2haml` executable.

Methods

Public Class methods

@param args [Array<String>] The command-line arguments

[Source]

     # File lib/haml/exec.rb, line 579
579:       def initialize(args)
580:         super
581:         @module_opts = {}
582:       end

Public Instance methods

Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.

[Source]

     # File lib/haml/exec.rb, line 622
622:       def process_result
623:         super
624: 
625:         require 'haml/html'
626: 
627:         input = @options[:input]
628:         output = @options[:output]
629: 
630:         @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
631:         @module_opts[:erb] &&= @options[:no_erb] != false
632: 
633:         output.write(::Haml::HTML.new(input, @module_opts).render)
634:       rescue ::Haml::Error => e
635:         raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
636:           "#{get_line e}: #{e.message}"
637:       rescue LoadError => err
638:         handle_load_error(err)
639:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 587
587:       def set_opts(opts)
588:         opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
589: 
590:         opts.on('-e', '--erb', 'Parse ERb tags.') do
591:           @module_opts[:erb] = true
592:         end
593: 
594:         opts.on('--no-erb', "Don't parse ERb tags.") do
595:           @options[:no_erb] = true
596:         end
597: 
598:         opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
599:           @module_opts[:erb] = true
600:         end
601: 
602:         opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
603:           @options[:no_erb] = true
604:         end
605: 
606:         opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
607:           @module_opts[:xhtml] = true
608:         end
609: 
610:         super
611:       end

[Validate]