Sha256: 22c36031c73e949b2f389b98b3863559d07c0afdd706227001937dc0c6e3e9de

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

require 'rubygems'
require 'bundler/setup'

require 'haml'

module RubyApp

  module Mixins

    module RenderMixin
      require 'ruby_app'

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

      def rendered?(file)
        unless RubyApp::Response.rendered?(file)
          yield
          RubyApp::Response.rendered(file)
        end
      end

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

      def render(format)

        templates = self.templates(format)

        unless templates.empty?

          self.init_haml_helpers unless @haml_buffer

          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::Response.get_content(self, templates[index - 1])
                else
                  _content = RubyApp::Response.get_content(self, arguments[0])
                  if self.block_is_haml?(_content)
                    self.capture_haml(arguments, &_content)
                  else
                    _content
                  end
                end
              end
              RubyApp::Response.content_for(self, template, content)
            end

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

          ensure
            RubyApp::Response.clear_content(self)
          end

        end
      end

    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
RubyApp-0.2.4 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.2.3 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.2.2 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.2.1 lib/ruby_app/mixins/render_mixin.rb
RubyApp-0.2.0 lib/ruby_app/mixins/render_mixin.rb