class Opulent::Template

@OpulentTemplate

Attributes

def[R]

Allow accessing engine definitions

Public Instance Methods

evaluate(scope, locals, &block) click to toggle source

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.

Calls superclass method
# 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 = {}) click to toggle source

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.

# File lib/opulent/template.rb, line 42
def precompiled_template(_locals = {})
  @engine.src
end
prepare() click to toggle source

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.

# File lib/opulent/template.rb, line 17
def prepare
  # Set up the rendering engine
  @options[:file] = eval_file
  @engine = ::Opulent.new @data, @options
end