Class: Servel::HamlContext
- Inherits:
-
Object
- Object
- Servel::HamlContext
- Extended by:
- Instrumentation
- Defined in:
- lib/servel/haml_context.rb
Constant Summary collapse
- LOCK =
Mutex.new
Class Method Summary collapse
Instance Method Summary collapse
- #haml_engine(path) ⇒ Object
- #include(path) ⇒ Object
-
#initialize ⇒ HamlContext
constructor
A new instance of HamlContext.
- #partial(name, locals = {}) ⇒ Object
- #render(template, locals = {}) ⇒ Object
Methods included from Instrumentation
Constructor Details
#initialize ⇒ HamlContext
Returns a new instance of HamlContext.
10 11 12 |
# File 'lib/servel/haml_context.rb', line 10 def initialize @build_path = Pathname.new(__FILE__).dirname.realpath + "../../app" end |
Class Method Details
.render(template, locals) ⇒ Object
6 7 8 |
# File 'lib/servel/haml_context.rb', line 6 def self.render(template, locals) [200, {}, [new.render(template, locals)]] end |
Instance Method Details
#haml_engine(path) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
22 23 24 |
# File 'lib/servel/haml_context.rb', line 22 def include(path) (@build_path + path).read end |
#partial(name, locals = {}) ⇒ Object
18 19 20 |
# File 'lib/servel/haml_context.rb', line 18 def partial(name, locals = {}) render("_#{name}.haml", locals) end |
#render(template, locals = {}) ⇒ Object
14 15 16 |
# File 'lib/servel/haml_context.rb', line 14 def render(template, locals = {}) haml_engine(template).render(self, locals) end |