Sha256: 3eaf3ed4bfc5376cbb1a039da1316e0b0af804e7e9044802330a19f6f8fa39f7

Contents?: true

Size: 1.67 KB

Versions: 25

Compression:

Stored size: 1.67 KB

Contents

module Elastics
  class Template
    module Common

      attr_reader :name, :partials, :tags, :data

      def setup(host_elastics, name=nil, *vars)
        @host_elastics = host_elastics
        @name         = name
        @source_vars  = Vars.new(*vars) if is_a?(Elastics::Template)
        self
      end

      def interpolate_partials(vars)
        @partials.each do |name|
          partial_assigned_vars = vars[name]
          next if Prunable::VALUES.include?(partial_assigned_vars)
          vars[name] = case partial_assigned_vars
                       when Array
                         partial_assigned_vars.map {|v| @host_elastics.partials[name].interpolate(vars, v)}
                       # other partial name (usable as a case output)
                       when Symbol
                         @host_elastics.partials[partial_assigned_vars].interpolate(vars, vars[partial_assigned_vars])
                       # a partial object
                       when Template::Partial
                         partial_assigned_vars.interpolate(vars, vars)
                       # on-the-fly partial creation (an empty string would prune it before)
                       when String
                         Template::Partial.new(partial_assigned_vars).interpolate(vars, vars)
                       # switch to include the partial (a false value would prune it before)
                       when TrueClass
                         @host_elastics.partials[name].interpolate(vars, vars)
                       else
                         @host_elastics.partials[name].interpolate(vars, partial_assigned_vars)
                       end
        end
        vars
      end

    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
elastics-client-1.3.3 lib/elastics/template/common.rb
elastics-client-1.3.2 lib/elastics/template/common.rb
elastics-client-1.3.1 lib/elastics/template/common.rb
elastics-client-1.3.0 lib/elastics/template/common.rb
elastics-client-1.2.1 lib/elastics/template/common.rb
elastics-client-1.2.0 lib/elastics/template/common.rb
elastics-client-1.1.11 lib/elastics/template/common.rb
elastics-client-1.1.10 lib/elastics/template/common.rb
elastics-client-1.1.9 lib/elastics/template/common.rb
elastics-client-1.1.8 lib/elastics/template/common.rb
elastics-client-1.1.7 lib/elastics/template/common.rb
elastics-client-1.1.6 lib/elastics/template/common.rb
elastics-client-1.1.5 lib/elastics/template/common.rb
elastics-client-1.1.4 lib/elastics/template/common.rb
elastics-client-1.1.3 lib/elastics/template/common.rb
elastics-client-1.1.2 lib/elastics/template/common.rb
elastics-client-1.1.1 lib/elastics/template/common.rb
elastics-client-1.1.0 lib/elastics/template/common.rb
elastics-client-1.0.10 lib/elastics/template/common.rb
elastics-client-1.0.9 lib/elastics/template/common.rb