Add library and support for partials
This commit is contained in:
17
Sources/HummingbirdMustache/Library.swift
Normal file
17
Sources/HummingbirdMustache/Library.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
public class HBMustacheLibrary {
|
||||
init() {
|
||||
self.templates = [:]
|
||||
}
|
||||
|
||||
public func register(_ template: HBMustacheTemplate, named name: String) {
|
||||
templates[name] = template
|
||||
}
|
||||
|
||||
public func render(_ object: Any, withTemplateNamed name: String) -> String? {
|
||||
guard let template = templates[name] else { return nil }
|
||||
return template.render(object, library: self)
|
||||
}
|
||||
|
||||
var templates: [String: HBMustacheTemplate]
|
||||
}
|
||||
Reference in New Issue
Block a user