Class: Servel::HamlContext
- Inherits:
-
Object
- Object
- Servel::HamlContext
- Extended by:
- Instrumentation
- Includes:
- ActiveSupport::NumberHelper
- 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.
11 12 13 |
# File 'lib/servel/haml_context.rb', line 11 def initialize @build_path = Pathname.new(__FILE__).dirname.realpath + "../../app" end |
Class Method Details
.render(template, locals) ⇒ Object
7 8 9 |
# File 'lib/servel/haml_context.rb', line 7 def self.render(template, locals) [200, {}, [new.render(template, locals)]] end |
Instance Method Details
#haml_engine(path) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/servel/haml_context.rb', line 27 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
23 24 25 |
# File 'lib/servel/haml_context.rb', line 23 def include(path) (@build_path + path).read end |
#partial(name, locals = {}) ⇒ Object
19 20 21 |
# File 'lib/servel/haml_context.rb', line 19 def partial(name, locals = {}) render("_#{name}.haml", locals) end |
#render(template, locals = {}) ⇒ Object
15 16 17 |
# File 'lib/servel/haml_context.rb', line 15 def render(template, locals = {}) haml_engine(template).render(self, locals) end |