Sha256: e0c80b58464f3c3128da8e2a7c03d9ec4c3440769d49e315684e78855652f748

Contents?: true

Size: 1.25 KB

Versions: 49

Compression:

Stored size: 1.25 KB

Contents

require 'tilt/template'

module Tilt
  # Liquid template implementation. See:
  # http://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.
  class LiquidTemplate < Template
    def self.engine_initialized?
      defined? ::Liquid::Template
    end

    def initialize_engine
      require_template_library 'liquid'
    end

    def prepare
      @engine = ::Liquid::Template.parse(data)
    end

    def evaluate(scope, locals, &block)
      locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
      if scope.respond_to?(:to_h)
        scope  = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
        locals = scope.merge(locals)
      end
      locals['yield'] = block.nil? ? '' : yield
      locals['content'] = locals['yield']
      @engine.render(locals)
    end

    def allows_script?
      false
    end
  end
end

Version data entries

49 entries across 42 versions & 11 rubygems

Version Path
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/lib/tilt/liquid.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/tilt-1.3.4/lib/tilt/liquid.rb
challah-1.0.0 vendor/bundle/gems/tilt-1.4.1/lib/tilt/liquid.rb
swipe-rails-0.0.5 vendor/bundle/gems/tilt-1.4.1/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.7/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.5/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/tilt-1.3.5/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/tilt-1.3.5/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.5/lib/tilt/liquid.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.7/lib/tilt/liquid.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.3.7/lib/tilt/liquid.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.4.1/lib/tilt/liquid.rb
tilt-1.4.1 lib/tilt/liquid.rb
tilt-1.4.0 lib/tilt/liquid.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/liquid.rb
challah-1.0.0.beta2 vendor/bundle/gems/tilt-1.3.7/lib/tilt/liquid.rb
challah-1.0.0.beta vendor/bundle/gems/tilt-1.3.6/lib/tilt/liquid.rb
tilt-1.3.7 lib/tilt/liquid.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/liquid.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/liquid.rb