Class: Haml::Exec::HTML2Haml

Inherits:
Generic show all
Defined in:
/var/www/sass-pages/.haml/lib/haml/exec.rb

Overview

The html2haml executable.

Constant Summary

Instance Method Summary

Methods inherited from Generic

#color, #get_line, #parse, #parse!, #puts_action, #to_s

Constructor Details

- (HTML2Haml) initialize(args)

A new instance of HTML2Haml

Parameters:

  • (Array<String>) args — The command-line arguments


561
562
563
564
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 561

def initialize(args)
  super
  @module_opts = {}
end

Instance Method Details

- process_result

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



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 604

def process_result
  super

  require 'haml/html'

  input = @options[:input]
  output = @options[:output]

  @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
  @module_opts[:erb] &&= @options[:no_erb] != false

  output.write(::Haml::HTML.new(input, @module_opts).render)
rescue ::Haml::Error => e
  raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
    "#{get_line e}: #{e.message}"
rescue LoadError => err
  handle_load_error(err)
end

- set_opts(opts)

Tells optparse how to parse the arguments.

Parameters:

  • (OptionParser) opts


569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 569

def set_opts(opts)
  opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"

  opts.on('-e', '--erb', 'Parse ERb tags.') do
    @module_opts[:erb] = true
  end

  opts.on('--no-erb', "Don't parse ERb tags.") do
    @options[:no_erb] = true
  end

  opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
    @module_opts[:erb] = true
  end

  opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
    @options[:no_erb] = true
  end

  opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
    @module_opts[:xhtml] = true
  end

  super
end