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 561
561:       def initialize(args)
562:         super
563:         @module_opts = {}
564:       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 604
604:       def process_result
605:         super
606: 
607:         require 'haml/html'
608: 
609:         input = @options[:input]
610:         output = @options[:output]
611: 
612:         @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
613:         @module_opts[:erb] &&= @options[:no_erb] != false
614: 
615:         output.write(::Haml::HTML.new(input, @module_opts).render)
616:       rescue ::Haml::Error => e
617:         raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
618:           "#{get_line e}: #{e.message}"
619:       rescue LoadError => err
620:         handle_load_error(err)
621:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 569
569:       def set_opts(opts)
570:         opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
571: 
572:         opts.on('-e', '--erb', 'Parse ERb tags.') do
573:           @module_opts[:erb] = true
574:         end
575: 
576:         opts.on('--no-erb', "Don't parse ERb tags.") do
577:           @options[:no_erb] = true
578:         end
579: 
580:         opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
581:           @module_opts[:erb] = true
582:         end
583: 
584:         opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
585:           @options[:no_erb] = true
586:         end
587: 
588:         opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
589:           @module_opts[:xhtml] = true
590:         end
591: 
592:         super
593:       end

[Validate]