Class: Foresite::Renderer
- Inherits:
-
Object
- Object
- Foresite::Renderer
- Defined in:
- lib/foresite/renderer.rb
Overview
Renderer class.
Basic implementation of ERB for a path to a given template and variables.
Class Method Summary collapse
-
.render(path, vars) ⇒ String
Statically renders template with variables.
Instance Method Summary collapse
-
#initialize(path, vars) ⇒ Renderer
constructor
Constructor.
-
#render ⇒ String
Renders template with variables.
Constructor Details
#initialize(path, vars) ⇒ Renderer
Constructor.
13 14 15 16 17 18 19 20 21 |
# File 'lib/foresite/renderer.rb', line 13 def initialize(path, vars) @path = path @vars_original = @vars vars.each do |k, v| if k.is_a?(Symbol) instance_variable_set(:"@#{k}", v) end end end |
Class Method Details
.render(path, vars) ⇒ String
Statically renders template with variables.
40 41 42 |
# File 'lib/foresite/renderer.rb', line 40 def self.render(path, vars) new(path, vars).render end |
Instance Method Details
#render ⇒ String
Renders template with variables.
28 29 30 |
# File 'lib/foresite/renderer.rb', line 28 def render ::ERB.new(File.read(@path), trim_mode: "-").result(binding) end |