Skip to content

Commit

Permalink
Fixed bug with template caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismoos committed Jun 23, 2010
1 parent 0bc6958 commit 0e01dcd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/fastr/template.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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={})
Expand Down
4 changes: 2 additions & 2 deletions lib/fastr/template/erubis.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fastr/template/haml.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0e01dcd

Please sign in to comment.