Class: Tilt::LiquidTemplate

Inherits:
Template show all
Defined in:
lib/tilt/liquid.rb

Overview

Liquid template implementation. See: liquidmarkup.org/

Liquid is designed to be a safe template system and therefore does not provide direct access to execuatable scopes. In order to support a scope, the scope must be able to represent itself as a hash by responding to #to_h. If the scope does not respond to #to_h it will be ignored.

LiquidTemplate does not support yield blocks.

It’s suggested that your program require ‘liquid’ at load time when using this template engine.

Instance Attribute Summary

Attributes inherited from Template

#compiled_path, #data, #file, #line, #options

Instance Method Summary collapse

Methods inherited from Template

#basename, #compiled_method, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#allows_script?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/tilt/liquid.rb', line 36

def allows_script?
  false
end

#evaluate(scope, locs) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/tilt/liquid.rb', line 25

def evaluate(scope, locs)
  locals = {}
  if scope.respond_to?(:to_h)
    scope.to_h.each{|k, v| locals[k.to_s] = v}
  end
  locs.each{|k, v| locals[k.to_s] = v}
  locals['yield'] = block_given? ? yield : ''
  locals['content'] = locals['yield']
  @engine.render(locals)
end

#prepareObject



20
21
22
23
# File 'lib/tilt/liquid.rb', line 20

def prepare
  @options[:line_numbers] = true unless @options.has_key?(:line_numbers)
  @engine = ::Liquid::Template.parse(@data, @options)
end