| Class | Haml::Exec::HTML2Haml |
| In: |
lib/haml/exec.rb
|
| Parent: | Generic |
The `html2haml` executable.
@param args [Array<String>] The command-line arguments
# File lib/haml/exec.rb, line 590
590: def initialize(args)
591: super
592: @module_opts = {}
593: end
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
# File lib/haml/exec.rb, line 633
633: def process_result
634: super
635:
636: require 'haml/html'
637:
638: input = @options[:input]
639: output = @options[:output]
640:
641: @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
642: @module_opts[:erb] &&= @options[:no_erb] != false
643:
644: output.write(::Haml::HTML.new(input, @module_opts).render)
645: rescue ::Haml::Error => e
646: raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
647: "#{get_line e}: #{e.message}"
648: rescue LoadError => err
649: handle_load_error(err)
650: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 598
598: def set_opts(opts)
599: opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
600:
601: opts.on('-e', '--erb', 'Parse ERb tags.') do
602: @module_opts[:erb] = true
603: end
604:
605: opts.on('--no-erb', "Don't parse ERb tags.") do
606: @options[:no_erb] = true
607: end
608:
609: opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
610: @module_opts[:erb] = true
611: end
612:
613: opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
614: @options[:no_erb] = true
615: end
616:
617: opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
618: @module_opts[:xhtml] = true
619: end
620:
621: super
622: end