Module: Intranet::Core::HamlWrapper

Defined in:
lib/intranet/core/haml_wrapper.rb

Overview

Wrapps the Haml engine from the Haml gem. This module has to be included in any class wanting to generate a HTML/XML from HAML templates.

Instance Method Summary collapse

Instance Method Details

#to_markup(template, content = {}) ⇒ String

Generate the HTML/XML from a given HAML template.

Parameters:

  • template (String)

    The name of the HAML template to use.

  • content (Hash) (defaults to: {})

    The additional content required to generate the HTML/XML.

Returns:

  • (String)

    The HTML/XML content.



40
41
42
43
44
45
46
47
48
# File 'lib/intranet/core/haml_wrapper.rb', line 40

def to_markup(template, content = {})
  opts = { escape_html: false }
  engine = Haml::Template.new(opts) do
    File.read(find_template(template))
  end
  engine.render(self, content)
rescue Errno::ENOENT # template file does not exists
  ''
end