require 'haml'

module AvoidMetreon
  # A simple HAML renderer, that takes a template name and data.
  class HamlRenderer
    attr_reader :templates_path

    def initialize(templates_path:)
      @templates_path = templates_path
    end

    def render(template_name, locals)
      file_name = File.join(templates_path, "#{template_name}.haml")
      engine = Haml::Engine.new(File.read(file_name))
      engine.render(self, locals)
    end
  end
end

Add extremely simple HAML renderer.
Add extremely simple HAML renderer.

Allows you to render a file from the specified templates directory.
Since it passes itself in as the render context, this allows partials to
be rendered as well from within a template.
