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 370 370: def initialize(args) 371: super 372: 373: @module_opts = {} 374: 375: begin 376: require 'haml/html' 377: rescue LoadError => err 378: dep = err.message.scan(/^no such file to load -- (.*)/)[0] 379: raise err if @options[:trace] || dep.nil? || dep.empty? 380: $stderr.puts "Required dependency #{dep} not found!\n Use --trace for backtrace." 381: exit 1 382: end 383: end
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
# File lib/haml/exec.rb, line 415 415: def process_result 416: super 417: 418: input = @options[:input] 419: output = @options[:output] 420: 421: @module_opts[:rhtml] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/ 422: @module_opts[:rhtml] &&= @options[:no_rhtml] != false 423: 424: output.write(::Haml::HTML.new(input, @module_opts).render) 425: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 388 388: def set_opts(opts) 389: opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n" 390: 391: opts.on('-r', '--rhtml', 'Parse RHTML tags.') do 392: @module_opts[:rhtml] = true 393: end 394: 395: opts.on('--no-rhtml', "Don't parse RHTML tags.") do 396: @options[:no_rhtml] = true 397: end 398: 399: opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do 400: @module_opts[:xhtml] = true 401: end 402: 403: super 404: end