Fix issue with indented partials (#19)

* Fix issue with indented partials

* Add test

* Add empty transform for string
This commit is contained in:
Adam Fowler
2023-01-14 08:50:51 +00:00
committed by GitHub
parent 185004fdce
commit fa56176223
4 changed files with 59 additions and 4 deletions

View File

@@ -27,14 +27,16 @@ extension HBMustacheTemplate {
if let indentation = context.indentation, indentation != "" {
for token in tokens {
if string.last == "\n" {
let renderedString = self.renderToken(token, context: &context)
if renderedString != "", string.last == "\n" {
string += indentation
}
string += self.renderToken(token, context: &context)
string += renderedString
}
} else {
for token in tokens {
string += self.renderToken(token, context: &context)
let result = self.renderToken(token, context: &context)
string += result
}
}
return string

View File

@@ -39,6 +39,8 @@ public extension StringProtocol {
/// - Returns: Result
func transform(_ name: String) -> Any? {
switch name {
case "empty":
return isEmpty
case "capitalized":
return capitalized
case "lowercased":