Skip to content

Commit

Permalink
Merge pull request Shopify#748 from Shopify/expose-tags
Browse files Browse the repository at this point in the history
Make Template.tags loop-able
  • Loading branch information
gauravmc committed Apr 25, 2016
2 parents 23d2bee + 5bb211d commit e4cf55b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/liquid/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Template
@@file_system = BlankFileSystem.new

class TagRegistry
include Enumerable

def initialize
@tags = {}
@cache = {}
Expand All @@ -41,6 +43,10 @@ def delete(tag_name)
@cache.delete(tag_name)
end

def each(&block)
@tags.each(&block)
end

private

def lookup_class(name)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/block_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def test_with_block
def test_with_custom_tag
Liquid::Template.register_tag("testtag", Block)
assert Liquid::Template.parse("{% testtag %} {% endtesttag %}")
ensure
Liquid::Template.tags.delete('testtag')
end

private
Expand Down
8 changes: 8 additions & 0 deletions test/unit/template_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ def test_tags_delete
Template.tags.delete('fake')
assert_nil Template.tags['fake']
end

def test_tags_can_be_looped_over
Template.register_tag('fake', FakeTag)
result = Template.tags.map { |name, klass| [name, klass] }
assert result.include?(["fake", "TemplateUnitTest::FakeTag"])
ensure
Template.tags.delete('fake')
end
end

0 comments on commit e4cf55b

Please sign in to comment.