Added SpecPartialsTests and fixed issues

This commit is contained in:
Adam Fowler
2021-03-17 18:30:55 +00:00
parent b4d6a518c7
commit 169a7bbbf4
6 changed files with 164 additions and 14 deletions

View File

@@ -5,9 +5,12 @@ extension HBMustacheTemplate {
/// - object: Object
/// - context: Context that render is occurring in. Contains information about position in sequence
/// - Returns: Rendered text
func render(_ object: Any, context: HBMustacheContext? = nil) -> String {
func render(_ object: Any, context: HBMustacheContext? = nil, indentation: String? = nil) -> String {
var string = ""
for token in tokens {
if let indentation = indentation, string.last == "\n" {
string += indentation
}
switch token {
case let .text(text):
string += text
@@ -31,9 +34,9 @@ extension HBMustacheTemplate {
let child = getChild(named: variable, from: object, method: method, context: context)
string += renderInvertedSection(child, parent: object, with: template)
case let .partial(name):
if let text = library?.render(object, withTemplate: name) {
string += text
case let .partial(name, indentation):
if let template = library?.getTemplate(named: name) {
string += template.render(object, indentation: indentation)
}
}
}