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 528
528:       def initialize(args)
529:         super
530:         @module_opts = {}
531:       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 571
571:       def process_result
572:         super
573: 
574:         require 'haml/html'
575: 
576:         input = @options[:input]
577:         output = @options[:output]
578: 
579:         @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
580:         @module_opts[:erb] &&= @options[:no_erb] != false
581: 
582:         output.write(::Haml::HTML.new(input, @module_opts).render)
583:       rescue ::Haml::Error => e
584:         raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
585:           "#{get_line e}: #{e.message}"
586:       rescue LoadError => err
587:         handle_load_error(err)
588:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 536
536:       def set_opts(opts)
537:         opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
538: 
539:         opts.on('-e', '--erb', 'Parse ERb tags.') do
540:           @module_opts[:erb] = true
541:         end
542: 
543:         opts.on('--no-erb', "Don't parse ERb tags.") do
544:           @options[:no_erb] = true
545:         end
546: 
547:         opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
548:           @module_opts[:erb] = true
549:         end
550: 
551:         opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
552:           @options[:no_erb] = true
553:         end
554: 
555:         opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
556:           @module_opts[:xhtml] = true
557:         end
558: 
559:         super
560:       end

[Validate]