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 543 543: def initialize(args) 544: super 545: @module_opts = {} 546: end
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
# File lib/haml/exec.rb, line 586 586: def process_result 587: super 588: 589: require 'haml/html' 590: 591: input = @options[:input] 592: output = @options[:output] 593: 594: @module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/ 595: @module_opts[:erb] &&= @options[:no_erb] != false 596: 597: output.write(::Haml::HTML.new(input, @module_opts).render) 598: rescue ::Haml::Error => e 599: raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " + 600: "#{get_line e}: #{e.message}" 601: rescue LoadError => err 602: handle_load_error(err) 603: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 551 551: def set_opts(opts) 552: opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n" 553: 554: opts.on('-e', '--erb', 'Parse ERb tags.') do 555: @module_opts[:erb] = true 556: end 557: 558: opts.on('--no-erb', "Don't parse ERb tags.") do 559: @options[:no_erb] = true 560: end 561: 562: opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do 563: @module_opts[:erb] = true 564: end 565: 566: opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do 567: @options[:no_erb] = true 568: end 569: 570: opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do 571: @module_opts[:xhtml] = true 572: end 573: 574: super 575: end