Add support for dynamic partials
This commit is contained in:
@@ -192,6 +192,7 @@ final class TemplateRendererTests: XCTestCase {
|
||||
""")
|
||||
}
|
||||
|
||||
/// Testing partials
|
||||
func testMustacheManualExample9() throws {
|
||||
let library = HBMustacheLibrary()
|
||||
let template = try HBMustacheTemplate(string: """
|
||||
@@ -215,4 +216,28 @@ final class TemplateRendererTests: XCTestCase {
|
||||
|
||||
""")
|
||||
}
|
||||
|
||||
/// Testing dynamic partials
|
||||
func testDynamicPartials() throws {
|
||||
let library = HBMustacheLibrary()
|
||||
let template = try HBMustacheTemplate(string: """
|
||||
<h2>Names</h2>
|
||||
{{partial}}
|
||||
""")
|
||||
let template2 = try HBMustacheTemplate(string: """
|
||||
{{#names}}
|
||||
<strong>{{.}}</strong>
|
||||
{{/names}}
|
||||
""")
|
||||
library.register(template, named: "base")
|
||||
|
||||
let object: [String: Any] = ["names": ["john", "adam", "claire"], "partial": template2]
|
||||
XCTAssertEqual(library.render(object, withTemplateNamed: "base"), """
|
||||
<h2>Names</h2>
|
||||
<strong>john</strong>
|
||||
<strong>adam</strong>
|
||||
<strong>claire</strong>
|
||||
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user