Class: ServerlessRedirector::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/serverless_redirector/renderer.rb

Constant Summary collapse

BASE_PATH =
::File.expand_path '../../templates', File.dirname(__FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_name) ⇒ Renderer

Returns a new instance of Renderer.



11
12
13
14
# File 'lib/serverless_redirector/renderer.rb', line 11

def initialize(template_name)
  @template_name = template_name
  @template_path = ::File.join BASE_PATH, template_name
end

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name.



9
10
11
# File 'lib/serverless_redirector/renderer.rb', line 9

def template_name
  @template_name
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



9
10
11
# File 'lib/serverless_redirector/renderer.rb', line 9

def template_path
  @template_path
end

Instance Method Details

#render(context = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/serverless_redirector/renderer.rb', line 16

def render(context = {})
  contents = ::File.read(template_path)
  template = ERB.new contents
  ctx_binding = OpenStruct.new(context).instance_eval { binding }
  template.result ctx_binding
end