Sha256: abb853d12726f48651e2a7cebc51bc546e8a9e473c3c04fb5de96ace1593812c

Contents?: true

Size: 1.86 KB

Versions: 145

Compression:

Stored size: 1.86 KB

Contents

require 'rubygems'
require 'bundler/setup'

require 'haml'

module RubyApp

  module Mixins

    module RenderMixin
      require 'ruby_app'

      def get_templates(format)
        return self.is_a?(Class) ? super(format) : self.class.get_templates(format)
      end

      def get_default_template
        return self.is_a?(Class) ? super : self.class.get_default_template
      end

      def get_cache(format)
        return self.is_a?(Class) ? super(format) : self.class.get_cache(format)
      end

      def content_for(format, name, value = nil, &block)
        return RubyApp::Response.content_for(self, format, name, value, &block)
      end

      def render(format)

        templates = self.get_templates(format)

        unless templates.empty?

          self.init_haml_helpers unless @haml_buffer

          yield(self) if block_given?

          templates.each_with_index do |template, index|

            if RubyApp::Response.rendered?(self, template)
              template = self.get_default_template
              templates[index] = template
            end

            content = Haml::Engine.new(File.read(template), :filename => template).render(self) do |*arguments|
              if arguments.empty?
                index == 0 ? nil : RubyApp::Response.get_content(self, format, templates[index - 1])
              else
                _content = RubyApp::Response.get_content(self, format, arguments[0])
                if self.block_is_haml?(_content)
                  self.capture_haml(arguments, &_content)
                else
                  _content
                end
              end
            end

            RubyApp::Response.rendered(self, template)
            RubyApp::Response.content_for(self, format, template, content)

          end

          return RubyApp::Response.get_content(self, format, templates.last)

        end
      end

    end

  end

end

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
RubyApp-0.7.16 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.15 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.14 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.13 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.12 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.11 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.10 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.9 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.5 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.4 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.3 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.2 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.1 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.7.0 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.71 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.70 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.69 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.68 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.67 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.6.66 lib/ruby_app/mixins/render_mixin.rb