Sha256: 63a4baf29d78f3140734bdb0916d0860184175bc55fa834a7d6e3b16db7d2eb5

Contents?: true

Size: 785 Bytes

Versions: 1

Compression:

Stored size: 785 Bytes

Contents

class Servel::HamlContext
  include ActiveSupport::NumberHelper

  ENGINE_OPTIONS = { remove_whitespace: true, escape_html: true, ugly: true }

  def initialize()
    @build_path = Pathname.new(__FILE__).dirname.realpath + 'templates'
    @haml_engine_cache = {}
  end

  def render(template, locals = {})
    haml_engine(template).render(self, locals)
  end

  def partial(name, locals = {})
    render("_#{name}.haml", locals)
  end

  def include(path)
    (@build_path + path).read
  end

  def decorate(path)
    Servel::PathnameDecorator.new(pathname: path)
  end

  def haml_engine(path)
    unless @haml_engine_cache.key?(path)
      @haml_engine_cache[path] = Haml::Engine.new(include(path), ENGINE_OPTIONS.merge(filename: path))
    end
    @haml_engine_cache[path]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
servel-0.5.0 lib/servel/haml_context.rb