Class: Haml2html::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/haml2html/converter.rb

Constant Summary collapse

VOID_TAGS =
%w[area base br col embed hr img input link meta param source track wbr].freeze
SUPPORTED_FILTERS =
%w[plain escaped javascript css erb].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}) ⇒ Converter

Returns a new instance of Converter.



15
16
17
18
19
20
# File 'lib/haml2html/converter.rb', line 15

def initialize(template, options = {})
  @template = template.respond_to?(:read) ? template.read : template.to_s
  @lines = @template.lines
  @filename = options[:filename]
  @diagnostics = []
end

Instance Attribute Details

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



13
14
15
# File 'lib/haml2html/converter.rb', line 13

def diagnostics
  @diagnostics
end

Instance Method Details

#renderObject

Raises:



22
23
24
25
26
27
28
# File 'lib/haml2html/converter.rb', line 22

def render
  ast = Haml::Parser.new(filename: @filename).call(@template)
  output = emit_children(ast.children, 0)
  raise ConversionError, diagnostics if diagnostics.any?

  output
end