Template inheritance (#9)
* Move all context variables into HBMustacheContext * Add support for reading inherited sections * Render inherited tokens * Test inheritance spec, fix two minor issues * fix warning * swift format
This commit is contained in:
@@ -11,7 +11,7 @@ public final class HBMustacheTemplate {
|
||||
/// - Parameter object: Object to render
|
||||
/// - Returns: Rendered text
|
||||
public func render(_ object: Any) -> String {
|
||||
self.render([object], context: nil)
|
||||
self.render(context: .init(object))
|
||||
}
|
||||
|
||||
internal init(_ tokens: [Token]) {
|
||||
@@ -22,8 +22,10 @@ public final class HBMustacheTemplate {
|
||||
self.library = library
|
||||
for token in self.tokens {
|
||||
switch token {
|
||||
case .section(_, _, let template), .invertedSection(_, _, let template):
|
||||
case .section(_, _, let template), .invertedSection(_, _, let template), .inheritedSection(_, let template):
|
||||
template.setLibrary(library)
|
||||
case .partial(_, _, let templates):
|
||||
templates?.forEach { $1.setLibrary(library) }
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -36,7 +38,8 @@ public final class HBMustacheTemplate {
|
||||
case unescapedVariable(name: String, method: String? = nil)
|
||||
case section(name: String, method: String? = nil, template: HBMustacheTemplate)
|
||||
case invertedSection(name: String, method: String? = nil, template: HBMustacheTemplate)
|
||||
case partial(String, indentation: String?)
|
||||
case inheritedSection(name: String, template: HBMustacheTemplate)
|
||||
case partial(String, indentation: String?, inherits: [String: HBMustacheTemplate]?)
|
||||
}
|
||||
|
||||
let tokens: [Token]
|
||||
|
||||
Reference in New Issue
Block a user