Class: Octopolo::Renderer
- Inherits:
-
Object
- Object
- Octopolo::Renderer
- Defined in:
- lib/octopolo/renderer.rb
Constant Summary collapse
- PULL_REQUEST_BODY =
Constants for the template file names
"pull_request_body"
- ISSUE_BODY =
"issue_body"
Class Method Summary collapse
-
.contents_of(template) ⇒ Object
Public: The contents of the named template.
-
.render(template, locals) ⇒ Object
Public: Render a given ERB template.
-
.template_base_path ⇒ Object
Public: Path to the directory containing the templates.
Class Method Details
.contents_of(template) ⇒ Object
Public: The contents of the named template
29 30 31 |
# File 'lib/octopolo/renderer.rb', line 29 def self.contents_of template File.read File.join(template_base_path, "#{template}.erb") end |
.render(template, locals) ⇒ Object
Public: Render a given ERB template
template - A String contianing the name of the ERB template locals - A Hash containing variables to render. The keys must match the variable names in the template
Lifted from [Stack Overflow](stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash)
Example
render "first_last_name_template", {first: "Bob", last: "Person"}
# => "Bob Person"
Returns a String containing the rendered template
23 24 25 26 |
# File 'lib/octopolo/renderer.rb', line 23 def self.render template, locals # template_string, safe_mode = 0, "-" to trim whitespace in ERB tags ending -%> (like Rails) ERB.new(contents_of(template), 0, "-").result(OpenStruct.new(locals).instance_eval { binding }) end |
.template_base_path ⇒ Object
Public: Path to the directory containing the templates
34 35 36 |
# File 'lib/octopolo/renderer.rb', line 34 def self.template_base_path File.(File.join(__FILE__, "../templates")) end |