Sha256: 17da0b611fc72c095a814521c92280bb2a2e076fe8f212d1d0d03782e5009913

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 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 the requested format.
        #
        # @return [Symbol] the requested format (eg. :html, :json, :xml, etc..)
        #
        # @since 0.1.0
        def format
          locals[:format]
        end

        protected
        def method_missing(m, *args)
          if @view.respond_to?(m)
            @view.__send__ m, *args
          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.2.0 lib/lotus/view/rendering/scope.rb