Method: Vedeu::DSL::Composition#template_for

Defined in:
lib/vedeu/dsl/composition.rb

#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Views::Views<Vedeu::Views::View>

TODO:

More documentation required.

Load content from an ERb template.

Examples:

Vedeu.renders do
  template_for(:my_interface,
               '/path/to/template.erb',
               @some_object, options)
end

Parameters:

  • name (String|Symbol)

    The name of interface for which this template’s content belongs to.

  • filename (String)

    The filename (including path) to the template to be used. Yoy can use ‘File.dirname(__FILE__)` to use relative paths.

  • object (Object) (defaults to: nil)

    The object for which the values of template’s variables can be obtained.

  • options (Hash<Symbol => void>) (defaults to: {})

Returns:

Raises:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vedeu/dsl/composition.rb', line 95

def template_for(name, filename, object = nil, options = {})
  fail Vedeu::Error::MissingRequired,
       'Cannot render template without the name of the ' \
       'view.'.freeze unless name
  fail Vedeu::Error::MissingRequired,
       'Cannot render template without a filename.'.freeze unless filename

  options.merge!(name: name)

  content = Vedeu::Templating::ViewTemplate.parse(object,
                                                  filename,
                                                  options)

  # lines     = Vedeu::Output::Wordwrap.for(content, options)

  new_model = model.member.build(template_attributes(name, content))

  model.add(new_model)
end