Module: RubyApp::Mixins::RenderMixin
Instance Method Summary collapse
- #clear_content_for ⇒ Object
- #content_for(name, value = nil, &block) ⇒ Object
- #render(format) ⇒ Object
- #rendered?(template) ⇒ Boolean
Instance Method Details
#clear_content_for ⇒ Object
32 33 34 35 |
# File 'lib/ruby_app/mixins/render_mixin.rb', line 32 def clear_content_for ( @_content ||= {} )[Thread.current] ||= {} @_content.delete(Thread.current) end |
#content_for(name, value = nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_app/mixins/render_mixin.rb', line 21 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 end |
#render(format) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_app/mixins/render_mixin.rb', line 37 def render(format) self.init_haml_helpers begin yield(self) if block_given? templates = self.is_a?(Class) ? self.get_templates(format) : self.class.get_templates(format) templates.each_with_index do |template, index| #RubyApp::Log.debug("#{self.is_a?(Class) ? self : self.class}##{__method__} template=#{File.expand_path(template)}") 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]) else _content = self.content_for(arguments[0]) if self.block_is_haml?(_content) self.capture_haml(arguments, &_content) else _content end end end self.content_for(template, content) end self.content_for(templates.last) ensure self.clear_content_for end end |
#rendered?(template) ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/ruby_app/mixins/render_mixin.rb', line 14 def rendered?(template) unless ( Thread.current[:_rendered] ||= {} ).key?(template) yield Thread.current[:_rendered][template] = ( Thread.current[:_rendered][template] || 0 ) + 1 end end |