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 362 362: def initialize(args) 363: super 364: 365: @module_opts = {} 366: 367: begin 368: require 'haml/html' 369: rescue LoadError => err 370: dep = err.message.scan(/^no such file to load -- (.*)/)[0] 371: raise err if @options[:trace] || dep.nil? || dep.empty? 372: $stderr.puts "Required dependency #{dep} not found!\n Use --trace for backtrace." 373: exit 1 374: end 375: end
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
# File lib/haml/exec.rb, line 407 407: def process_result 408: super 409: 410: input = @options[:input] 411: output = @options[:output] 412: 413: @module_opts[:rhtml] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/ 414: @module_opts[:rhtml] &&= @options[:no_rhtml] != false 415: 416: output.write(::Haml::HTML.new(input, @module_opts).render) 417: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 380 380: def set_opts(opts) 381: opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n" 382: 383: opts.on('-r', '--rhtml', 'Parse RHTML tags.') do 384: @module_opts[:rhtml] = true 385: end 386: 387: opts.on('--no-rhtml', "Don't parse RHTML tags.") do 388: @options[:no_rhtml] = true 389: end 390: 391: opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do 392: @module_opts[:xhtml] = true 393: end 394: 395: super 396: end