Sha256: 8c82970e79ed21de657a65a7382740d51eb067bfa11b62572c4852829626b63f

Contents?: true

Size: 775 Bytes

Versions: 2

Compression:

Stored size: 775 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
      GlobalCache.add_filter(filter)
    end

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

    GlobalCache = Class.new(StrainerTemplate)

    private

    def strainer_from_cache(filters)
      if filters.empty?
        GlobalCache
      else
        strainer_class_cache[filters] ||= begin
          klass = Class.new(GlobalCache)
          filters.each { |f| klass.add_filter(f) }
          klass
        end
      end
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
liquid-5.3.0 lib/liquid/strainer_factory.rb
liquid-5.2.0 lib/liquid/strainer_factory.rb