diff --git a/lib/liquid.rb b/lib/liquid.rb index 6f071a8a6..a64e8c188 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -52,7 +52,6 @@ module Liquid require "liquid/version" require "liquid/deprecations" require "liquid/const" -require "liquid/template/tag_registry" require 'liquid/standardfilters' require 'liquid/file_system' require 'liquid/parser_switching' diff --git a/lib/liquid/environment.rb b/lib/liquid/environment.rb index fdd404fcd..31b17b234 100644 --- a/lib/liquid/environment.rb +++ b/lib/liquid/environment.rb @@ -41,7 +41,7 @@ class << self # @return [Environment] The new environment instance. def build(tags: nil, file_system: nil, error_mode: nil, exception_renderer: nil) ret = new - ret.tags = Template::TagRegistry.new(tags) if tags + ret.tags = tags if tags ret.file_system = file_system if file_system ret.error_mode = error_mode if error_mode ret.exception_renderer = exception_renderer if exception_renderer @@ -74,7 +74,7 @@ def dangerously_override(environment) # Initializes a new environment instance. # @api private def initialize - @tags = Template::TagRegistry.new(Tags::STANDARD_TAGS) + @tags = Tags::STANDARD_TAGS.dup @error_mode = :lax @strainer_template = Class.new(StrainerTemplate).tap do |klass| klass.add_filter(StandardFilters) diff --git a/lib/liquid/template/tag_registry.rb b/lib/liquid/template/tag_registry.rb deleted file mode 100644 index d055ad2e0..000000000 --- a/lib/liquid/template/tag_registry.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -module Liquid - class Template - class TagRegistry - include Enumerable - - def initialize(tags = nil) - @tags = {} - @cache = {} - tags.each { |tag_name, klass| self[tag_name] = klass } - Deprecations.warn("Template::TagRegistry", "Use a Environment instance with zeitwerk") - end - - def [](tag_name) - return nil unless @tags.key?(tag_name) - return @cache[tag_name] if Liquid.cache_classes - - lookup_class(@tags[tag_name]).tap { |o| @cache[tag_name] = o } - end - - def delete(tag_name) - Deprecations.warn("Template::TagRegistry#delete", "Use a Environment instance with immutable tags") - @tags.delete(tag_name) - @cache.delete(tag_name) - end - - def []=(tag_name, klass) - @tags[tag_name] = klass.name - @cache[tag_name] = klass - end - - def each(&block) - @tags.each(&block) - end - - private - - def lookup_class(name) - Object.const_get(name) - end - end - end -end diff --git a/test/unit/template_unit_test.rb b/test/unit/template_unit_test.rb index f44cd1538..e5c248694 100644 --- a/test/unit/template_unit_test.rb +++ b/test/unit/template_unit_test.rb @@ -39,31 +39,12 @@ def test_with_cache_classes_tags_returns_the_same_class Liquid.cache_classes = original_cache_setting end - def test_without_cache_classes_tags_reloads_the_class - original_cache_setting = Liquid.cache_classes - Liquid.cache_classes = false - - original_klass = Class.new - Object.send(:const_set, :CustomTag, original_klass) - with_custom_tag('custom', CustomTag) do - Object.send(:remove_const, :CustomTag) - - new_klass = Class.new - Object.send(:const_set, :CustomTag, new_klass) - - assert(Template.tags['custom'].equal?(new_klass)) - end - ensure - Object.send(:remove_const, :CustomTag) - Liquid.cache_classes = original_cache_setting - end - class FakeTag; end def test_tags_can_be_looped_over with_custom_tag('fake', FakeTag) do result = Template.tags.map { |name, klass| [name, klass] } - assert(result.include?(["fake", "TemplateUnitTest::FakeTag"])) + assert(result.include?(["fake", TemplateUnitTest::FakeTag])) end end