Class: Jaspion::Miya::Template
- Inherits:
-
Object
- Object
- Jaspion::Miya::Template
- Defined in:
- lib/jaspion/miya/template.rb
Overview
Represents a result file template that can be manipulated
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Template file path.
-
#object ⇒ Object
Object object that template is related to.
Class Method Summary collapse
-
.dir_path ⇒ String
Returns all available classes.
Instance Method Summary collapse
- #default_file_path ⇒ Object
-
#initialize(object = nil, path = nil) ⇒ Template
constructor
Initializes an Template object.
- #save(path) ⇒ Object
-
#source_code ⇒ String
Returns the parsed template code using ERUBIS The template file should be in /template directory.
Constructor Details
#initialize(object = nil, path = nil) ⇒ Template
Initializes an Template object
> If path == nil, it tries to figure out the path by Object class name
31 32 33 34 |
# File 'lib/jaspion/miya/template.rb', line 31 def initialize(object = nil, path = nil) @object = object @file_path = (path || default_file_path) end |
Instance Attribute Details
#file_path ⇒ Object
Template file path
14 15 16 |
# File 'lib/jaspion/miya/template.rb', line 14 def file_path @file_path end |
#object ⇒ Object
Object object that template is related to
11 12 13 |
# File 'lib/jaspion/miya/template.rb', line 11 def object @object end |
Class Method Details
.dir_path ⇒ String
Returns all available classes
20 21 22 |
# File 'lib/jaspion/miya/template.rb', line 20 def dir_path File.(File.join(__FILE__, '..', '..', '..', 'templates')) end |
Instance Method Details
#default_file_path ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/jaspion/miya/template.rb', line 36 def default_file_path unless object.nil? path_components = object.class.name.split('::')[1..-1] path_components[0] = self.class.dir_path return File.join(*path_components.map(&:downcase)) + '.erb' end end |
#save(path) ⇒ Object
53 54 |
# File 'lib/jaspion/miya/template.rb', line 53 def save(path) end |
#source_code ⇒ String
Returns the parsed template code using ERUBIS The template file should be in /template directory
48 49 50 51 |
# File 'lib/jaspion/miya/template.rb', line 48 def source_code return nil if @file_path.nil? || !File.file?(@file_path) Erubis::Eruby.new(File.read(@file_path)).evaluate(object) end |