Class: Ree::RenderUtils

Inherits:
Object show all
Defined in:
lib/ree/utils/render_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locals = {}) ⇒ RenderUtils

Returns a new instance of RenderUtils.



10
11
12
13
# File 'lib/ree/utils/render_utils.rb', line 10

def initialize(locals = {})
  @render_binding = binding
  @locals         = locals
end

Class Method Details

.render(template, locals) ⇒ Object



6
7
8
# File 'lib/ree/utils/render_utils.rb', line 6

def self.render(template, locals)
  new(locals).render(template)
end

Instance Method Details

#render(template) ⇒ Object



15
16
17
18
19
# File 'lib/ree/utils/render_utils.rb', line 15

def render(template)
  @locals.each { |variable, value| @render_binding.local_variable_set(variable, value) }

  ERB.new(template).result(@render_binding)
end