class Haml::Exec::HTML2Haml
The ‘html2haml` executable.
def initialize(args)
-
args
(Array
) -- The command-line arguments
def initialize(args) super @module_opts = {} begin require 'haml/html' rescue LoadError => err dep = err.message.scan(/^no such file to load -- (.*)/)[0] puts "Required dependency #{dep} not found!" exit 1 end end
def process_result
Processes the options set by the command-line arguments,
def process_result super input = @options[:input] output = @options[:output] @module_opts[:rhtml] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/ @module_opts[:rhtml] &&= @options[:no_rhtml] != false output.write(::Haml::HTML.new(input, @module_opts).render) end
def set_opts(opts)
-
opts
(OptionParser
) --
def set_opts(opts) opts.banner = <<END html2haml [options] [INPUT] [OUTPUT] ption: Transforms an HTML file into corresponding Haml code. s: opts.on('-r', '--rhtml', 'Parse RHTML tags.') do @module_opts[:rhtml] = true end opts.on('--no-rhtml', "Don't parse RHTML tags.") do @options[:no_rhtml] = true end opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do @module_opts[:xhtml] = true end super end