class Servel::HamlContext

Constants

LOCK

Public Class Methods

new() click to toggle source
# File lib/servel/haml_context.rb, line 10
def initialize
  @build_path = Pathname.new(__FILE__).dirname.realpath + "../../app"
end
render(template, locals) click to toggle source
# File lib/servel/haml_context.rb, line 6
def self.render(template, locals)
  [200, {}, [new.render(template, locals)]]
end

Public Instance Methods

haml_engine(path) click to toggle source
# File lib/servel/haml_context.rb, line 26
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
include(path) click to toggle source
# File lib/servel/haml_context.rb, line 22
def include(path)
  (@build_path + path).read
end
partial(name, locals = {}) click to toggle source
# File lib/servel/haml_context.rb, line 18
def partial(name, locals = {})
  render("_#{name}.haml", locals)
end
render(template, locals = {}) click to toggle source
# File lib/servel/haml_context.rb, line 14
def render(template, locals = {})
  haml_engine(template).render(self, locals)
end