Sha256: 6e88959990d69ff99d571fd9325462adc7b84a83f5440d67bedb561c4dfed373

Contents?: true

Size: 769 Bytes

Versions: 5

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

module Liquid
  # StrainerFactory is the factory for the filters system.
  module StrainerFactory
    extend self

    def add_global_filter(filter)
      strainer_class_cache.clear
      global_filters << filter
    end

    def create(context, filters = [])
      strainer_from_cache(filters).new(context)
    end

    private

    def global_filters
      @global_filters ||= []
    end

    def strainer_from_cache(filters)
      strainer_class_cache[filters] ||= begin
        klass = Class.new(StrainerTemplate)
        global_filters.each { |f| klass.add_filter(f) }
        filters.each { |f| klass.add_filter(f) }
        klass
      end
    end

    def strainer_class_cache
      @strainer_class_cache ||= {}
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
liquid-5.1.0 lib/liquid/strainer_factory.rb
liquid-5.0.1 lib/liquid/strainer_factory.rb
liquid-5.0.0 lib/liquid/strainer_factory.rb
liquid-render-tag-0.2.0 lib/liquid-render-tag/strainer_factory.rb
liquid-render-tag-0.1.0 lib/liquid-render-tag/strainer_factory.rb