From 0e01dcd47af85fedc926549ad0b07253dd176b8b Mon Sep 17 00:00:00 2001 From: Chris Moos Date: Tue, 22 Jun 2010 21:46:12 -0700 Subject: [PATCH] Fixed bug with template caching. --- lib/fastr/template.rb | 5 ++++- lib/fastr/template/erubis.rb | 4 ++-- lib/fastr/template/haml.rb | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fastr/template.rb b/lib/fastr/template.rb index 65d954f..e438082 100644 --- a/lib/fastr/template.rb +++ b/lib/fastr/template.rb @@ -60,6 +60,9 @@ def self.register_extensions(engine, extensions) end def render(kind, tpl, opts={}) + # Read the cache template settings for this application, unless it is passed in + opts[:cache_template] = self.app.settings.cache_templates unless opts[:cache_template] + case kind.to_sym when :template then render_template(tpl, opts) @@ -87,7 +90,7 @@ def render_template_to_string(tpl_path, opts={}) end @vars = opts[:vars] || {} - engine.result(tpl_path, binding()) + engine.result(tpl_path, binding(), opts[:cache_template]) end def render_text(text, opts={}) diff --git a/lib/fastr/template/erubis.rb b/lib/fastr/template/erubis.rb index 5a280df..4e978fe 100644 --- a/lib/fastr/template/erubis.rb +++ b/lib/fastr/template/erubis.rb @@ -4,9 +4,9 @@ module Fastr module Template class Erubis - def self.result(tpl_path, _binding) + def self.result(tpl_path, _binding, cache_template) eruby = Fastr::Template::TEMPLATE_CACHE[tpl_path] - unless eruby + unless eruby and cache_template eruby = ::Erubis::Eruby.new(File.read("app/views/#{tpl_path}")) Fastr::Template::TEMPLATE_CACHE[tpl_path] = eruby end diff --git a/lib/fastr/template/haml.rb b/lib/fastr/template/haml.rb index 7e874c7..573da74 100644 --- a/lib/fastr/template/haml.rb +++ b/lib/fastr/template/haml.rb @@ -6,7 +6,7 @@ class Haml def self.result(tpl_path, _binding) engine = Fastr::Template::TEMPLATE_CACHE[tpl_path] - unless engine + unless engine and cache_template engine = ::Haml::Engine.new(File.read("app/views/#{tpl_path}")) Fastr::Template::TEMPLATE_CACHE[tpl_path] = engine end