Class: Servel::HamlContext
- Inherits:
-
Object
- Object
- Servel::HamlContext
- Defined in:
- lib/servel/haml_context.rb
Constant Summary collapse
- ENGINE_OPTIONS =
{ remove_whitespace: true, escape_html: true, ugly: true }
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
Constructor Details
#initialize ⇒ HamlContext
4 5 6 7 |
# File 'lib/servel/haml_context.rb', line 4 def initialize() @build_path = Pathname.new(__FILE__).dirname.realpath + 'templates' @haml_engine_cache = {} end |
Instance Method Details
#haml_engine(path) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/servel/haml_context.rb', line 21 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 |
#include(path) ⇒ Object
17 18 19 |
# File 'lib/servel/haml_context.rb', line 17 def include(path) (@build_path + path).read end |
#partial(name, locals = {}) ⇒ Object
13 14 15 |
# File 'lib/servel/haml_context.rb', line 13 def partial(name, locals = {}) render("_#{name}.haml", locals) end |
#render(template, locals = {}) ⇒ Object
9 10 11 |
# File 'lib/servel/haml_context.rb', line 9 def render(template, locals = {}) haml_engine(template).render(self, locals) end |