Sha256: ff9ab80dd611a2f8d647c7fca32efcc3d4ca0bf718d55bd0b8597f5dd06a19ab

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'rubygems'
require 'bundler/setup'

require 'haml'

module RubyApp

  module Mixins

    module RenderMixin
      require 'ruby_app/request'

      def rendered?(template)
        unless RubyApp::Request.rendered?(template)
          yield
          RubyApp::Request.rendered(template)
        end
      end

      def content_for(name, value = nil, &block)
        RubyApp::Request.content_for(self, name, value, &block)
      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 : RubyApp::Request.get_content(self, templates[index - 1])
                else
                  _content = RubyApp::Request.get_content(self, arguments[0])
                  if self.block_is_haml?(_content)
                    self.capture_haml(arguments, &_content)
                  else
                    _content
                  end
                end
              end
              RubyApp::Request.content_for(self, template, content)
            end
            return RubyApp::Request.get_content(self, templates.last)
          ensure
            RubyApp::Request.clear_content(self)
          end
        end

      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
RubyApp-0.0.70 lib/ruby_app/mixins/render_mixin.rb