Class: Sinatra::Base
- Inherits:
-
Object
- Object
- Sinatra::Base
- Defined in:
- lib/sinatra/template_cache.rb
Overview
Caches Haml templates in Class instance “render_haml_#template” methods, avoiding reparsing and recompiling of the template on every page reload.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_cache! ⇒ Object
-
#haml(template, options = {}, locals = {}) ⇒ Object
Override function responsible for calling internal Haml rendering routines.
- #render_haml(template, data, options, locals, &block) ⇒ Object
Class Method Details
.clear_cache! ⇒ Object
23 24 25 |
# File 'lib/sinatra/template_cache.rb', line 23 def self.clear_cache! instance_methods.grep(/^render_haml_/).each{|m| remove_method m} end |
Instance Method Details
#clear_cache! ⇒ Object
26 |
# File 'lib/sinatra/template_cache.rb', line 26 def clear_cache!; self.class.clear_cache! end |
#haml(template, options = {}, locals = {}) ⇒ Object
Override function responsible for calling internal Haml rendering routines
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sinatra/template_cache.rb', line 8 def haml(template, ={}, locals={}) method = "render_haml_#{template}".to_sym return super(template, , locals) unless self.respond_to? method locals = .delete(:locals) || locals || {} if [:layout] != false __send__(:render_haml_layout, locals) { __send__(method, locals) } else __send__(method, locals) end end |
#render_haml(template, data, options, locals, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/sinatra/template_cache.rb', line 18 def render_haml(template, data, , locals, &block) method = "render_haml_#{template}".to_sym ::Haml::Engine.new(data, ).def_method(self.class, method, *(locals.keys)) __send__(method, locals, &block) end |