class Jaspion::Miya::Template
Represents a result file template that can be manipulated
Attributes
file_path[RW]
Template
file path
object[RW]
Object
object that template is related to
Public Class Methods
dir_path()
click to toggle source
Returns all available classes
@return [String] Directory path of /template
# File lib/jaspion/miya/template.rb, line 20 def dir_path File.expand_path(File.join(__FILE__, '..', '..', '..', 'templates')) end
new(object = nil, path = nil)
click to toggle source
Initializes an Template
object
@param object [Object] Object
object related to this template
@param path [String] Source - template path
> If path == nil, it tries to figure out the path by Object
class name¶ ↑
# File lib/jaspion/miya/template.rb, line 31 def initialize(object = nil, path = nil) @object = object @file_path = (path || default_file_path) end
Public Instance Methods
default_file_path()
click to toggle source
# 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)
click to toggle source
# File lib/jaspion/miya/template.rb, line 53 def save(path) end
source_code()
click to toggle source
Returns the parsed template code using ERUBIS The template file should be in /template directory
@return [String] Parsed code
# 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