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

- old
+ new

@@ -1,63 +1,51 @@ require 'rubygems' require 'bundler/setup' -require 'facets/string/interpolate' require 'haml' module RubyApp module Mixins module RenderMixin + require 'ruby_app/request' def rendered?(template) - unless ( Thread.current[:_rendered] ||= {} ).key?(template) + unless RubyApp::Request.rendered?(template) yield - Thread.current[:_rendered][template] = ( Thread.current[:_rendered][template] || 0 ) + 1 + RubyApp::Request.rendered(template) end end def content_for(name, value = nil, &block) - ( @_content ||= {} )[Thread.current] ||= {} - if block_given? - @_content[Thread.current][name] = block - elsif value - @_content[Thread.current][name] = String.interpolate { value } - else - @_content[Thread.current][name] - end + RubyApp::Request.content_for(self, name, value, &block) end - def clear_content_for - ( @_content ||= {} )[Thread.current] ||= {} - @_content.delete(Thread.current) - end - def render(format) 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? templates.each_with_index do |template, index| content = Haml::Engine.new(File.read(template), :filename => template).render(self) do |*arguments| if arguments.empty? - index == 0 ? nil : self.content_for(templates[index - 1]) + index == 0 ? nil : RubyApp::Request.get_content(self, templates[index - 1]) else - _content = self.content_for(arguments[0]) + _content = RubyApp::Request.get_content(self, arguments[0]) if self.block_is_haml?(_content) self.capture_haml(arguments, &_content) else _content end end end - self.content_for(template, content) + RubyApp::Request.content_for(self, template, content) end - return self.content_for(templates.last) + return RubyApp::Request.get_content(self, templates.last) ensure - self.clear_content_for + RubyApp::Request.clear_content(self) end end end