Class: ErbTemplateRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/devlogs/render/erb_template_renderer.rb

Overview

ErbTemplateRenderer is a base class for rendering arbitrary ERB templates.

Direct Known Subclasses

IssueTemplateRenderer, LogTemplateRenderer

Constant Summary collapse

TIME_FORMAT_TEXT_ENTRY =
"%m-%d-%Y %k:%M"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_file_path) ⇒ ErbTemplateRenderer

Returns a new instance of ErbTemplateRenderer.



14
15
16
17
# File 'lib/devlogs/render/erb_template_renderer.rb', line 14

def initialize(template_file_path)
  @time = Time.new.strftime(TIME_FORMAT_TEXT_ENTRY)
  @template_file_path = template_file_path
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



10
11
12
# File 'lib/devlogs/render/erb_template_renderer.rb', line 10

def time
  @time
end

Instance Method Details

#get_bindingObject

rubocop:disable

For ERB



33
34
35
# File 'lib/devlogs/render/erb_template_renderer.rb', line 33

def get_binding
  binding
end

#renderObject

Runs the ERB rendering using the provided template file template_file_path



24
25
26
27
# File 'lib/devlogs/render/erb_template_renderer.rb', line 24

def render
  erb = ERB.new(File.read(@template_file_path))
  erb.result(get_binding)
end