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.

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)


33
34
35
# File 'lib/tilt/liquid.rb', line 33

def allows_script?
  false
end

#evaluate(scope, locs) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/tilt/liquid.rb', line 22

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



17
18
19
20
# File 'lib/tilt/liquid.rb', line 17

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