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