Class: Nydp::Html::HamlToHtml

Inherits:
Object
  • Object
show all
Defined in:
lib/nydp/html.rb

Instance Method Summary collapse

Instance Method Details

#convert_from_haml(convertible) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nydp/html.rb', line 35

def convert_from_haml convertible
  Haml::Engine.new(convertible, suppress_eval: true).render
rescue Exception => e
  if e.line
    lines = convertible.split(/\n/)
    beginning = e.line - 2
    beginning = 0 if beginning < 0
    selection = lines[beginning...(e.line + 1)].join "\n"
    "#{e.message}<br/>line #{e.line}<br/><br/><pre>#{selection}</pre>"
  else
    e.message
  end
end

#invoke(vm, args) ⇒ Object



49
50
51
# File 'lib/nydp/html.rb', line 49

def invoke vm, args
  vm.push_arg Nydp::StringAtom.new convert_from_haml(args.car.to_s)
end