Moving stuff about/renaming

This commit is contained in:
Adam Fowler
2021-03-14 10:19:51 +00:00
parent 06251739d7
commit 5f49dd6953
5 changed files with 54 additions and 89 deletions

View File

@@ -0,0 +1,28 @@
protocol HBMustacheSequence {
func renderSection(with template: HBMustacheTemplate) -> String
func renderInvertedSection(with template: HBMustacheTemplate) -> String
}
extension Sequence {
func renderSection(with template: HBMustacheTemplate) -> String {
var string = ""
for obj in self {
string += template.render(obj)
}
return string
}
func renderInvertedSection(with template: HBMustacheTemplate) -> String {
var iterator = makeIterator()
if iterator.next() == nil {
return template.render(self)
}
return ""
}
}
extension Array: HBMustacheSequence {}
extension ReversedCollection: HBMustacheSequence {}
extension EnumeratedSequence: HBMustacheSequence {}