Class | Tilt::LiquidTemplate |
In: |
lib/tilt/liquid.rb
|
Parent: | Template |
Liquid template implementation. See: liquid.rubyforge.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.
# File lib/tilt/liquid.rb, line 18 18: def self.engine_initialized? 19: defined? ::Liquid::Template 20: end
# File lib/tilt/liquid.rb, line 30 30: def evaluate(scope, locals, &block) 31: locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h } 32: if scope.respond_to?(:to_h) 33: scope = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h } 34: locals = scope.merge(locals) 35: end 36: locals['yield'] = block.nil? ? '' : yield 37: locals['content'] = locals['yield'] 38: @engine.render(locals) 39: end