The `haml` executable.
Processes the options set by the command-line arguments, and runs the Haml compiler appropriately.
# File lib/haml/exec.rb, line 523 523: def process_result 524: super 525: input = @options[:input] 526: output = @options[:output] 527: 528: template = input.read() 529: input.close() if input.is_a? File 530: 531: begin 532: engine = ::Haml::Engine.new(template, @options[:for_engine]) 533: if @options[:check_syntax] 534: puts "Syntax OK" 535: return 536: end 537: 538: @options[:load_paths].each {|p| $LOAD_PATH << p} 539: @options[:requires].each {|f| require f} 540: 541: if @options[:debug] 542: puts engine.precompiled 543: puts '=' * 100 544: end 545: 546: result = engine.to_html 547: rescue Exception => e 548: raise e if @options[:trace] 549: 550: case e 551: when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}" 552: when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.message}" 553: else raise "Exception on line #{get_line e}: #{e.message}\n Use --trace for backtrace." 554: end 555: end 556: 557: output.write(result) 558: output.close() if output.is_a? File 559: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 477 477: def set_opts(opts) 478: super 479: 480: opts.on('-t', '--style NAME', 481: 'Output style. Can be indented (default) or ugly.') do |name| 482: @options[:for_engine][:ugly] = true if name.to_sym == :ugly 483: end 484: 485: opts.on('-f', '--format NAME', 486: 'Output format. Can be xhtml (default), html4, or html5.') do |name| 487: @options[:for_engine][:format] = name.to_sym 488: end 489: 490: opts.on('-e', '--escape-html', 491: 'Escape HTML characters (like ampersands and angle brackets) by default.') do 492: @options[:for_engine][:escape_html] = true 493: end 494: 495: opts.on('-q', '--double-quote-attributes', 496: 'Set attribute wrapper to double-quotes (default is single).') do 497: @options[:for_engine][:attr_wrapper] = '"' 498: end 499: 500: opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file| 501: @options[:requires] << file 502: end 503: 504: opts.on('-I', '--load-path PATH', "Same as 'ruby -I'.") do |path| 505: @options[:load_paths] << path 506: end 507: 508: unless ::Haml::Util.ruby1_8? 509: opts.on('-E ex[:in]', 'Specify the default external and internal character encodings.') do |encoding| 510: external, internal = encoding.split(':') 511: Encoding.default_external = external if external && !external.empty? 512: Encoding.default_internal = internal if internal && !internal.empty? 513: end 514: end 515: 516: opts.on('--debug', "Print out the precompiled Ruby source.") do 517: @options[:debug] = true 518: end 519: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.