Class: Vedeu::Templating::Template Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



26
27
28
29
30
# File 'lib/vedeu/templating/template.rb', line 26

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

Instance Attribute Details

#objectClass (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Class)


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

def object
  @object
end

#optionsHash (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


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

def options
  @options
end

Class Method Details

.parse(object, path, options = {}) ⇒ Vedeu::Views::Stream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

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

Returns:



15
16
17
# File 'lib/vedeu/templating/template.rb', line 15

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

Instance Method Details

#loadString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


50
51
52
# File 'lib/vedeu/templating/template.rb', line 50

def load
  File.read(path)
end

#parseVedeu::Views::Stream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/vedeu/templating/template.rb', line 33

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

#pathString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

Raises:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vedeu/templating/template.rb', line 56

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