Class: Vedeu::Template

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

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, path) ⇒ Template

Returns a new instance of Vedeu::Template.

Parameters:

  • object (Class)
  • path (String)


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

#objectClass (readonly, protected)

Returns:

  • (Class)


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.

Parameters:

  • object (Class)
  • path (String)


9
10
11
# File 'lib/vedeu/support/template.rb', line 9

def self.parse(object, path)
  new(object, path).parse
end

Instance Method Details

#loadString (private)

Returns:

  • (String)


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

def load
  File.read(path)
end

#parsevoid

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

#pathString (private)

Returns:

  • (String)

Raises:

  • (MissingRequired)

    when the path is empty.

  • (MissingRequired)

    when the path does not exist.



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