lib/ruby_app/mixins/render_mixin.rb in RubyApp-0.0.70 vs lib/ruby_app/mixins/render_mixin.rb in RubyApp-0.0.71

- old
+ new

@@ -6,10 +6,11 @@ module RubyApp module Mixins module RenderMixin + require 'ruby_app/log' require 'ruby_app/request' def rendered?(template) unless RubyApp::Request.rendered?(template) yield @@ -20,10 +21,15 @@ def content_for(name, value = nil, &block) RubyApp::Request.content_for(self, name, value, &block) end def render(format) + cache = self.is_a?(Class) ? self.get_cache(format) : self.class.get_cache(format) + if File.exists?(cache) + RubyApp::Log.debug("#{RubyApp::Log.prefix(self, __method__)} File.read(#{cache.inspect})") + File.read(cache) + end templates = self.is_a?(Class) ? self.get_templates(format) : self.class.get_templates(format) unless templates.empty? self.init_haml_helpers begin yield(self) if block_given? @@ -39,9 +45,18 @@ _content end end end RubyApp::Request.content_for(self, template, content) + end + if cache && RubyApp::Request.cache? + RubyApp::Log.debug("#{RubyApp::Log.prefix(self, __method__)} File.open(#{cache.inspect}, 'w')") + cache_directory = File.dirname(cache) + Dir.mkdir(cache_directory) unless File.exists?(cache_directory) + File.open(cache, 'w') do |file| + file.write(RubyApp::Request.get_content(self, templates.last)) + file.flush + end end return RubyApp::Request.get_content(self, templates.last) ensure RubyApp::Request.clear_content(self) end