Class: Haml::Exec::HTML2Haml

Inherits:
Generic show all
Defined in:
lib/haml/exec.rb

Overview

A class encapsulating executable functionality specific to the html2haml executable.

Instance Method Summary collapse

Methods inherited from Generic

#parse!, #to_s

Constructor Details

#initialize(args) ⇒ HTML2Haml

:nodoc:



307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/haml/exec.rb', line 307

def initialize(args)
  super

  @module_opts = {}

  begin
    require 'haml/html'
  rescue LoadError => err
    dep = err.message.scan(/^no such file to load -- (.*)/)[0]
    puts "Required dependency #{dep} not found!"
    exit 1
  end
end

Instance Method Details

#process_resultObject



345
346
347
348
349
350
351
352
353
354
355
# File 'lib/haml/exec.rb', line 345

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



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/haml/exec.rb', line 321

def set_opts(opts)
  opts.banner = <<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