Fix issues from Inheritance spec (#36)
* Separate inheritance block and expansion * Catch top level partial definition, and block newlines * Add testTrailingNewLines to verify output of trailing newlines in partials * Remove comment * If block,partial has indentation add indent for first line * Re-enable full sections spec * withBlockExpansion * Get indentation of blocks correct
This commit is contained in:
@@ -28,7 +28,8 @@ extension MustacheTemplate {
|
||||
if let indentation = context.indentation, indentation != "" {
|
||||
for token in tokens {
|
||||
let renderedString = self.renderToken(token, context: &context)
|
||||
if renderedString != "", string.last == "\n" {
|
||||
// if rendered string is not empty and we are on a new line
|
||||
if renderedString.count > 0, string.last == "\n" {
|
||||
string += indentation
|
||||
}
|
||||
string += renderedString
|
||||
@@ -75,11 +76,11 @@ extension MustacheTemplate {
|
||||
let child = self.getChild(named: variable, transforms: transforms, context: context)
|
||||
return self.renderInvertedSection(child, with: template, context: context)
|
||||
|
||||
case .inheritedSection(let name, let template):
|
||||
case .blockExpansion(let name, let defaultTemplate, let indented):
|
||||
if let override = context.inherited?[name] {
|
||||
return override.render(context: context)
|
||||
return override.render(context: context.withBlockExpansion(indented: indented))
|
||||
} else {
|
||||
return template.render(context: context)
|
||||
return defaultTemplate.render(context: context.withBlockExpansion(indented: indented))
|
||||
}
|
||||
|
||||
case .partial(let name, let indentation, let overrides):
|
||||
@@ -89,6 +90,9 @@ extension MustacheTemplate {
|
||||
|
||||
case .contentType(let contentType):
|
||||
context = context.withContentType(contentType)
|
||||
|
||||
case .blockDefinition:
|
||||
fatalError("Should not be rendering block definitions")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user