Skip to content

Commit

Permalink
Make tag registry enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravmc committed Apr 25, 2016
1 parent 23d2bee commit 6adc431
Show file tree
Hide file tree
Showing 2 changed files with 12 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
6 changes: 6 additions & 0 deletions test/unit/template_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ 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"])
end
end

0 comments on commit 6adc431

Please sign in to comment.