Class: Vedeu::Template
- Inherits:
-
Object
- Object
- Vedeu::Template
- Defined in:
- lib/vedeu/support/template.rb
Overview
Generic class to loading a template and parsing it via ERb.
Instance Attribute Summary collapse
- #object ⇒ Class readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, path) ⇒ Template
constructor
Returns a new instance of Vedeu::Template.
- #load ⇒ String private
- #parse ⇒ void
- #path ⇒ String private
Constructor Details
#initialize(object, path) ⇒ Template
Returns a new instance of Vedeu::Template.
18 19 20 21 |
# File 'lib/vedeu/support/template.rb', line 18 def initialize(object, path) @object = object @path = path.to_s end |
Instance Attribute Details
#object ⇒ Class (readonly, protected)
32 33 34 |
# File 'lib/vedeu/support/template.rb', line 32 def object @object end |
Class Method Details
.parse(object, path) ⇒ void
This method returns an undefined value.
9 10 11 |
# File 'lib/vedeu/support/template.rb', line 9 def self.parse(object, path) new(object, path).parse end |
Instance Method Details
#load ⇒ String (private)
37 38 39 |
# File 'lib/vedeu/support/template.rb', line 37 def load File.read(path) end |
#parse ⇒ void
This method returns an undefined value.
24 25 26 |
# File 'lib/vedeu/support/template.rb', line 24 def parse ERB.new(load, nil, '-').result(binding) end |
#path ⇒ String (private)
44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/support/template.rb', line 44 def path fail MissingRequired, 'No path to template specified.' if @path.empty? unless File.exist?(@path) fail MissingRequired, 'Template file cannot be found.' end @path end |