Class: Opulent::Template

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/opulent/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defObject (readonly)

Allow accessing engine definitions



6
7
8
# File 'lib/opulent/template.rb', line 6

def def
  @def
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object

Execute the compiled template and return the result string. Template evaluation is guaranteed to be performed in the scope object with the locals specified and with support for yielding to the block.

This method is only used by source generating templates. Subclasses that override render() may not support all features.



30
31
32
33
# File 'lib/opulent/template.rb', line 30

def evaluate(scope, locals, &block)
  fail ArgumentError, 'Invalid scope: must not be frozen.' if scope.frozen?
  super
end

#precompiled_template(_locals = {}) ⇒ Object

A string containing the (Ruby) source code for the template. The default Template#evaluate implementation requires either this method or the #precompiled method be overridden. When defined, the base Template guarantees correct file/line handling, locals support, custom scopes, proper encoding, and support for template compilation.



42
43
44
# File 'lib/opulent/template.rb', line 42

def precompiled_template(_locals = {})
  @engine.src
end

#prepareObject

Do whatever preparation is necessary to setup the underlying template engine. Called immediately after template data is loaded. Instance variables set in this method are available when #evaluate is called.

Subclasses must provide an implementation of this method.



17
18
19
20
21
# File 'lib/opulent/template.rb', line 17

def prepare
  # Set up the rendering engine
  @options[:file] = eval_file
  @engine = ::Opulent.new @data, @options
end