Module: Hanami::View::Rendering::InstanceMethods
- Defined in:
- lib/hanami/view/rendering.rb
Overview
Instance Method Summary collapse
-
#initialize(template, **locals) ⇒ Object
Initialize a view.
-
#local(key) ⇒ Object, Hanami::View::Rendering::NullLocal
It tries to invoke a method for the view or a local for the given key.
-
#render ⇒ String
Render the template by bounding the local scope.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m) ⇒ Object (protected)
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.
Delegates missing methods to the scope.
199 200 201 |
# File 'lib/hanami/view/rendering.rb', line 199 def method_missing(m, *) @scope.__send__ m end |
Instance Method Details
#initialize(template, **locals) ⇒ Object
Initialize a view
42 43 44 45 46 |
# File 'lib/hanami/view/rendering.rb', line 42 def initialize(template, **locals) @template = template @locals = locals @scope = Scope.new(self, @locals) end |
#local(key) ⇒ Object, Hanami::View::Rendering::NullLocal
It tries to invoke a method for the view or a local for the given key. If the lookup fails, it returns a null object.
122 123 124 125 126 127 128 |
# File 'lib/hanami/view/rendering.rb', line 122 def local(key) if respond_to?(key) __send__(key) else locals.fetch(key) { NullLocal.new(key) } end end |
#render ⇒ String
Render the template by bounding the local scope. If it uses a layout, it renders the template first and then the control passes to the layout.
Override this method for custom rendering policies. For instance, when a serializer is used and there isn’t the need of a template.
107 108 109 |
# File 'lib/hanami/view/rendering.rb', line 107 def render layout.render end |