Class: Lotus::View::Rendering::Scope

Inherits:
LayoutScope show all
Defined in:
lib/lotus/view/rendering/scope.rb

Overview

Rendering scope

See Also:

Since:

  • 0.1.0

Instance Method Summary collapse

Methods inherited from LayoutScope

#class, #content, #locals, #render, #respond_to?, #view

Constructor Details

#initialize(view, locals = {}) ⇒ Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the scope

Parameters:

  • view (Class)

    the view

  • locals (Hash) (defaults to: {})

    a set of objects available during the rendering

Options Hash (locals):

  • :format (Symbol)

    the requested format

Since:

  • 0.1.0



23
24
25
# File 'lib/lotus/view/rendering/scope.rb', line 23

def initialize(view, locals = {})
  @view, @locals, @layout = view, locals, layout
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (protected)

Since:

  • 0.1.0



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lotus/view/rendering/scope.rb', line 62

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

Instance Method Details

#formatSymbol

Returns the requested format.

Returns:

  • (Symbol)

    the requested format (eg. :html, :json, :xml, etc..)

Since:

  • 0.1.0



44
45
46
# File 'lib/lotus/view/rendering/scope.rb', line 44

def format
  locals[:format]
end

#inspectString

Returns an inspect String

Returns:

  • (String)

    inspect String (contains classname, objectid in hex, available ivars)

Since:

  • 0.3.0



32
33
34
35
36
37
# File 'lib/lotus/view/rendering/scope.rb', line 32

def inspect
  base = "#<#{ self.class }: #{'%x' % (self.object_id << 1)}"
  base << " @view=\"#{@view}\"" if @view
  base << " @locals=\"#{@locals}\"" if @locals
  base << ">"
end

#respond_to_missing?(m, include_all) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Implements “respond to” logic

Returns:

  • (TrueClass, FalseClass)

See Also:

Since:

  • 0.3.0



56
57
58
59
# File 'lib/lotus/view/rendering/scope.rb', line 56

def respond_to_missing?(m, include_all)
  @view.respond_to?(m) ||
    @locals.key?(m)
end