Sha256: f043a6eba00155243d46ef477cc0f6a793f5c20cc11c860878b326054093104d

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

require 'lotus/view/rendering/layout_scope'
require 'lotus/view/rendering/template'
require 'lotus/view/rendering/partial'

module Lotus
  module View
    module Rendering
      # Rendering scope
      #
      # @since 0.1.0
      #
      # @see Lotus::View::Rendering::LayoutScope
      class Scope < LayoutScope
        # Initialize the scope
        #
        # @param view [Class] the view
        # @param locals [Hash] a set of objects available during the rendering
        # @option locals [Symbol] :format the requested format
        #
        # @api private
        # @since 0.1.0
        def initialize(view, locals = {})
          @view, @locals = view, locals
        end

        # Returns an inspect String
        #
        # @return [String] inspect String (contains classname, objectid in hex, available ivars)
        #
        # @since 0.3.0
        def inspect
          base = "#<#{ self.class }: #{'%x' % (self.object_id << 1)}"
          base << " @view=\"#{@view}\"" if @view
          base << " @locals=\"#{@locals}\"" if @locals
          base << ">"
        end

        # Returns the requested format.
        #
        # @return [Symbol] the requested format (eg. :html, :json, :xml, etc..)
        #
        # @since 0.1.0
        def format
          locals[:format]
        end

        # Implements "respond to" logic
        #
        # @return [TrueClass,FalseClass]
        #
        # @since 0.3.0
        # @api private
        #
        # @see http://ruby-doc.org/core/Object.html#method-i-respond_to_missing-3F
        def respond_to_missing?(m, include_all)
          @view.respond_to?(m) ||
            @locals.key?(m)
        end

        protected
        def method_missing(m, *args, &block)
          if @view.respond_to?(m)
            @view.__send__ m, *args, &block
          elsif @locals.key?(m)
            @locals[m]
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lotus-view-0.3.0 lib/lotus/view/rendering/scope.rb