Class Tilt::LiquidTemplate
In: lib/sinatra/tilt.rb
Parent: Template
Template BuilderTemplate RDiscountTemplate LiquidTemplate RDocTemplate MustacheTemplate StringTemplate RedClothTemplate HamlTemplate ERBTemplate SassTemplate ErubisTemplate Cache lib/sinatra/tilt.rb Tilt dot/m_4_0.png

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.

Methods

Public Instance methods

[Source]

     # File lib/sinatra/tilt.rb, line 374
374:     def compile!
375:       @engine = ::Liquid::Template.parse(data)
376:     end

[Source]

     # File lib/sinatra/tilt.rb, line 378
378:     def evaluate(scope, locals, &block)
379:       locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
380:       if scope.respond_to?(:to_h)
381:         scope  = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
382:         locals = scope.merge(locals)
383:       end
384:       # TODO: Is it possible to lazy yield ?
385:       locals['yield'] = block.nil? ? '' : yield
386:       locals['content'] = block.nil? ? '' : yield
387:       @engine.render(locals)
388:     end

[Source]

     # File lib/sinatra/tilt.rb, line 370
370:     def initialize_engine
371:       require_template_library 'liquid' unless defined? ::Liquid::Template
372:     end

[Validate]