Class: Wright::Util::ErbRenderer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wright/util/erb_renderer.rb

Overview

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

ERB renderer.

Examples:

template = "foo is <%= foo %>."
hash = { foo: :bar }
Wright::Util::ErbRenderer.new(hash).render(template)
# => "foo is bar."

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ErbRenderer

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.

Returns a new instance of ErbRenderer.



13
14
15
16
17
18
19
# File 'lib/wright/util/erb_renderer.rb', line 13

def initialize(hash)
  hash.each do |k, v|
    instance_var = "@#{k}"
    instance_variable_set(instance_var, v)
    define_singleton_method(k) { instance_variable_get(instance_var) }
  end
end

Instance Method Details

#render(template) ⇒ String

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.

Renders an ERB template.

Parameters:

  • template (String)

    the template

Returns:

  • (String)

    the rendered template



24
25
26
# File 'lib/wright/util/erb_renderer.rb', line 24

def render(template)
  ERB.new(template).result(binding)
end