Sha256: 39655435d3ce410d1b4e87b72efd85c1f7eeb3ff2b636455a97c200e397bf354

Contents?: true

Size: 707 Bytes

Versions: 6

Compression:

Stored size: 707 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 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

6 entries across 6 versions & 1 rubygems

Version Path
servel-0.8.0 lib/servel/haml_context.rb
servel-0.7.0 lib/servel/haml_context.rb
servel-0.6.0 lib/servel/haml_context.rb
servel-0.4.0 lib/servel/haml_context.rb
servel-0.3.0 lib/servel/haml_context.rb
servel-0.2.0 lib/servel/haml_context.rb