Sha256: 187d8b0cebe030dcf01e208c52a33e3c439f7e2431981291b33a8036be4ce46b

Contents?: true

Size: 1.11 KB

Versions: 25

Compression:

Stored size: 1.11 KB

Contents

require 'tilt/template'
require 'liquid'

module Tilt
  # Liquid template implementation. See:
  # http://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.
  class LiquidTemplate < Template
    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

25 entries across 25 versions & 7 rubygems

Version Path
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/tilt-2.0.5/lib/tilt/liquid.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/tilt-2.0.5/lib/tilt/liquid.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/tilt-2.0.5/lib/tilt/liquid.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/liquid.rb
tilt-2.0.5 lib/tilt/liquid.rb