Sha256: a4c1eda569d36accb3d858443d3aa772bccf9c6447c47af4e0bc05d65c7ae63f

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
require_relative 'template'
require 'liquid'

module Tilt
  # Liquid template implementation. See:
  # http://liquidmarkup.org/
  #
  # Liquid is designed to be a *safe* template system and therefore
  # 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
      @options[:line_numbers] = true unless @options.has_key?(:line_numbers)
      @engine = ::Liquid::Template.parse(@data, @options)
    end

    def evaluate(scope, locs)
      locals = {}
      if scope.respond_to?(:to_h)
        scope.to_h.each{|k, v| locals[k.to_s] = v}
      end
      locs.each{|k, v| locals[k.to_s] = v}
      locals['yield'] = block_given? ? yield : ''
      locals['content'] = locals['yield']
      @engine.render(locals)
    end

    def allows_script?
      false
    end
  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
brakeman-6.2.2 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/liquid.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/tilt-2.4.0/lib/tilt/liquid.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/liquid.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/liquid.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/tilt-2.4.0/lib/tilt/liquid.rb
tilt-2.4.0 lib/tilt/liquid.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/tilt-2.3.0/lib/tilt/liquid.rb
tilt-2.3.0 lib/tilt/liquid.rb
tilt-2.2.0 lib/tilt/liquid.rb