class Tilt::LiquidTemplate

Liquid template implementation. See: liquidmarkup.org/

Liquid is designed to be a safe template system and threfore 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.

Public Instance Methods

allows_script?() click to toggle source
   # File lib/tilt/liquid.rb
34 def allows_script?
35   false
36 end
evaluate(scope, locals) { || ... } click to toggle source
   # File lib/tilt/liquid.rb
23 def evaluate(scope, locals, &block)
24   locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
25   if scope.respond_to?(:to_h)
26     scope  = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
27     locals = scope.merge(locals)
28   end
29   locals['yield'] = block.nil? ? '' : yield
30   locals['content'] = locals['yield']
31   @engine.render(locals)
32 end
prepare() click to toggle source
   # File lib/tilt/liquid.rb
19 def prepare
20   @engine = ::Liquid::Template.parse(data, liquid_options)
21 end

Private Instance Methods

liquid_options() click to toggle source
   # File lib/tilt/liquid.rb
40 def liquid_options
41   { line_numbers: true }.merge options
42 end