79447838

Date: 2025-02-18 10:14:15
Score: 0.5
Natty:
Report link

There seem to be 2 options. Firstly, looking at the CHANGELOG for HAML v6.0.0 indicates that Template.new is a replacement for Engine.new:

engine = Haml::Template.new(--your haml file--)
html = engine.render(Object.new, { bar: 'hello, world!' })

(although the docs imply you can pass a string of HAML to Template.new, I found it didn't work and the parameter was interpreted as a file name. Maybe a change between 6.0.0 and 6.3.0?)

Alternatively, use the Tilt abstraction layer (as used by most of the web frameworks), which might insulate you from future HAML/template updates:

require 'tilt'
require 'tilt/haml'
engine = Tilt::HamlTemplate.new(--your haml file--)
html = engine.render(Object.new, { bar: 'hello, world!' })

Note: for Tilt, as above, the string parameter on 'new' is taken to be a filename where your HAML resides, not the actual HAML code itself.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Mike