Class: Vedeu::Templating::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/templating/template.rb

Overview

Generic class to loading a template and parsing it via ERb.

Direct Known Subclasses

ViewTemplate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, path, options = {}) ⇒ Vedeu::Templating::Template

Returns a new instance of Vedeu::Templating::Template.

Parameters:

  • object (Class)
  • path (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • name (String|Symbol)

    The name of an interface.



22
23
24
25
26
# File 'lib/vedeu/templating/template.rb', line 22

def initialize(object, path, options = {})
  @object  = object
  @path    = path.to_s
  @options = options || {}
end

Instance Attribute Details

#objectClass (readonly, protected)

Returns:

  • (Class)


37
38
39
# File 'lib/vedeu/templating/template.rb', line 37

def object
  @object
end

#optionsHash (readonly, protected)

Returns:

  • (Hash)


41
42
43
# File 'lib/vedeu/templating/template.rb', line 41

def options
  @options
end

Class Method Details

.parse(object, path, options = {}) ⇒ void

This method returns an undefined value.



11
12
13
# File 'lib/vedeu/templating/template.rb', line 11

def self.parse(object, path, options = {})
  new(object, path, options).parse
end

Instance Method Details

#loadString (private)

Returns:

  • (String)


46
47
48
# File 'lib/vedeu/templating/template.rb', line 46

def load
  File.read(path)
end

#parseVedeu::Views::Stream



29
30
31
# File 'lib/vedeu/templating/template.rb', line 29

def parse
  ERB.new(load, nil, '-').result(binding)
end

#pathString (private)

Returns:

  • (String)

Raises:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vedeu/templating/template.rb', line 53

def path
  fail Vedeu::Error::MissingRequired,
       'No path to template specified.'.freeze if @path.empty?

  unless File.exist?(@path)
    fail Vedeu::Error::MissingRequired,
         "Template file cannot be found. (#{@path})".freeze
  end

  @path
end