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 517
517:       def initialize(args)
518:         super
519:         @module_opts = {}
520:       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 560
560:       def process_result
561:         super
562: 
563:         require 'haml/html'
564: 
565:         input = @options[:input]
566:         output = @options[:output]
567: 
568:         @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
569:         @module_opts[:erb] &&= @options[:no_erb] != false
570: 
571:         output.write(::Haml::HTML.new(input, @module_opts).render)
572:       rescue ::Haml::Error => e
573:         raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
574:           "#{get_line e}: #{e.message}"
575:       rescue LoadError => err
576:         handle_load_error(err)
577:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 525
525:       def set_opts(opts)
526:         opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
527: 
528:         opts.on('-e', '--erb', 'Parse ERb tags.') do
529:           @module_opts[:erb] = true
530:         end
531: 
532:         opts.on('--no-erb', "Don't parse ERb tags.") do
533:           @options[:no_erb] = true
534:         end
535: 
536:         opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
537:           @module_opts[:erb] = true
538:         end
539: 
540:         opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
541:           @options[:no_erb] = true
542:         end
543: 
544:         opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
545:           @module_opts[:xhtml] = true
546:         end
547: 
548:         super
549:       end

[Validate]