Sha256: 37ca7359a97d767251b80c8777ffd987bc79be45643904cbdb844f9c685a96ec

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

class Servel::HamlContext
  extend Servel::Instrumentation
  include ActiveSupport::NumberHelper

  LOCK = Mutex.new

  def self.render(template, locals)
    [200, {}, [new.render(template, locals)]]
  end

  def initialize
    @build_path = Pathname.new(__FILE__).dirname.realpath + "../../app"
  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)
    LOCK.synchronize do
      @@haml_engine_cache ||= {}
      unless @@haml_engine_cache.key?(path)
        @@haml_engine_cache[path] = Hamlit::Template.new(filename: path) { include(path) }
      end
      @@haml_engine_cache[path]
    end
  end

  instrument :render, :partial, :include
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
servel-0.24.0 lib/servel/haml_context.rb
servel-0.23.0 lib/servel/haml_context.rb
servel-0.22.0 lib/servel/haml_context.rb
servel-0.21.0 lib/servel/haml_context.rb