Class: Vedeu::Templating::Template
- Inherits:
-
Object
- Object
- Vedeu::Templating::Template
- Defined in:
- lib/vedeu/templating/template.rb
Overview
Generic class to loading a template and parsing it via ERb.
Direct Known Subclasses
Instance Attribute Summary collapse
- #object ⇒ Class readonly protected
- #options ⇒ Hash readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, path, options = {}) ⇒ Vedeu::Templating::Template
constructor
Returns a new instance of Vedeu::Templating::Template.
- #load ⇒ String private
- #parse ⇒ Vedeu::Views::Stream
- #path ⇒ String private
Constructor Details
#initialize(object, path, options = {}) ⇒ Vedeu::Templating::Template
Returns a new instance of Vedeu::Templating::Template.
24 25 26 27 28 |
# File 'lib/vedeu/templating/template.rb', line 24 def initialize(object, path, = {}) @object = object @path = path.to_s @options = || {} end |
Instance Attribute Details
#object ⇒ Class (readonly, protected)
39 40 41 |
# File 'lib/vedeu/templating/template.rb', line 39 def object @object end |
#options ⇒ Hash (readonly, protected)
43 44 45 |
# File 'lib/vedeu/templating/template.rb', line 43 def @options end |
Class Method Details
.parse(object, path, options = {}) ⇒ Vedeu::Views::Stream
13 14 15 |
# File 'lib/vedeu/templating/template.rb', line 13 def self.parse(object, path, = {}) new(object, path, ).parse end |
Instance Method Details
#load ⇒ String (private)
48 49 50 |
# File 'lib/vedeu/templating/template.rb', line 48 def load File.read(path) end |
#parse ⇒ Vedeu::Views::Stream
31 32 33 |
# File 'lib/vedeu/templating/template.rb', line 31 def parse ERB.new(load, nil, '-').result(binding) end |
#path ⇒ String (private)
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vedeu/templating/template.rb', line 54 def path raise Vedeu::Error::MissingRequired, 'No path to template specified.' if @path.empty? unless File.exist?(@path) raise Vedeu::Error::MissingRequired, "Template file cannot be found. (#{@path})" end @path end |