Class: Sidewalk::TemplateHandlers::BaseDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/sidewalk/template_handlers/base_delegate.rb

Overview

A delegate scope to run templates in.

Used to provide templates access to the controller’s instance variables, and extra helper functions, without polluting the controller with them. For example, ErbHandler::Delegate will also include the standard ERB::Util helper functions like #h (aka #html_escape)

Direct Known Subclasses

ErbHandler::Delegate, RxhpHandler::Delegate

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ BaseDelegate

A new instance of delegate.

Copies all instance variables from controller to object.

Parameters:



16
17
18
19
20
21
22
23
# File 'lib/sidewalk/template_handlers/base_delegate.rb', line 16

def initialize controller
  controller.instance_variables.each do |name|
    self.instance_variable_set(
      name,
      controller.instance_variable_get(name)
    )
  end
end

Instance Method Details

#renderObject

Render the template in the scope.

The default implementation raises a NotImplementedError.

Examples:

ErbDelegate#render

def render
  # @template is set by {ErbDelegate}'s constructor.
  @template.result binding
end

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/sidewalk/template_handlers/base_delegate.rb', line 34

def render
  raise NotImplementedError.new
end