In Files

Haml::Exec::HTML2Haml

The `html2haml` executable.

Public Class Methods

new(args) click to toggle source

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

# File lib/haml/exec.rb, line 300
def initialize(args)
  super
  @module_opts = {}
end

Public Instance Methods

process_result() click to toggle source

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

# File lib/haml/exec.rb, line 342
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) click to toggle source

Tells optparse how to parse the arguments.

@param opts [OptionParser]

# File lib/haml/exec.rb, line 308
def set_opts(opts)
  opts.banner = Usage: html2haml [options] [INPUT] [OUTPUT]Description: Transforms an HTML file into corresponding Haml code.Options:

  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

[Validate]

Generated with the Darkfish Rdoc Generator 2.