Class: Haml::Exec::HTML2Haml
Overview
The ‘html2haml` executable.
Instance Method Summary collapse
-
#initialize(args) ⇒ HTML2Haml
constructor
A new instance of HTML2Haml.
-
#process_result ⇒ Object
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
-
#set_opts(opts) ⇒ Object
Tells optparse how to parse the arguments.
Methods inherited from Generic
Constructor Details
#initialize(args) ⇒ HTML2Haml
Returns a new instance of HTML2Haml.
359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/haml/exec.rb', line 359 def initialize(args) super @module_opts = {} begin require 'haml/html' rescue LoadError => err dep = err..scan(/^no such file to load -- (.*)/)[0] puts "Required dependency #{dep} not found!" exit 1 end end |
Instance Method Details
#process_result ⇒ Object
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/haml/exec.rb', line 402 def process_result super input = @options[:input] output = @options[:output] @module_opts[:rhtml] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/ @module_opts[:rhtml] &&= @options[:no_rhtml] != false output.write(::Haml::HTML.new(input, @module_opts).render) end |
#set_opts(opts) ⇒ Object
Tells optparse how to parse the arguments.
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/haml/exec.rb', line 376 def set_opts(opts) opts. = <<END Usage: html2haml [options] [INPUT] [OUTPUT] Description: Transforms an HTML file into corresponding Haml code. Options: END opts.on('-r', '--rhtml', 'Parse RHTML tags.') do @module_opts[:rhtml] = true end opts.on('--no-rhtml', "Don't parse RHTML tags.") do @options[:no_rhtml] = true end opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do @module_opts[:xhtml] = true end super end |