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
BOOLEAN_ATTRIBUTES =
%w[
  allowfullscreen async autofocus autoplay checked compact controls declare default defaultchecked defaultmuted
  defaultselected defer disabled enabled formnovalidate hidden indeterminate inert ismap itemscope loop multiple
  muted nohref nomodule noresize noshade novalidate nowrap open pauseonexit playsinline readonly required
  reversed scoped seamless selected sortable truespeed typemustmatch visible
].freeze
SUPPORTED_FILTERS =
%w[plain escaped javascript css erb ruby].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Converter.



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

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.



20
21
22
# File 'lib/haml2html/converter.rb', line 20

def diagnostics
  @diagnostics
end

Instance Method Details

#renderObject

Raises:



29
30
31
32
33
34
35
# File 'lib/haml2html/converter.rb', line 29

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

  output
end