HBMustacheLibrary
public final class HBMustacheLibrary
Class holding a collection of mustache templates.
Each template can reference the others via a partial using the name the template is registered under
{{#sequence}}{{>entry}}{{/sequence}}
-
Initialize empty library
Declaration
Swift
public init()
-
Initialize library with contents of folder.
Each template is registered with the name of the file minus its extension. The search through the folder is recursive and templates in subfolders will be registered with the name
subfolder/template
.Declaration
Swift
public init(directory: String, withExtension extension: String = "mustache") throws
Parameters
directory
Directory to look for mustache templates
extension
Extension of files to look for
-
Register template under name
Declaration
Swift
public func register(_ template: HBMustacheTemplate, named name: String)
Parameters
template
Template
name
Name of template
-
Register template under name
Declaration
Swift
public func register(_ mustache: String, named name: String) throws
Parameters
mustache
Mustache text
name
Name of template
-
Return template registed with name
Declaration
Swift
public func getTemplate(named name: String) -> HBMustacheTemplate?
Parameters
name
name to search for
Return Value
Template
-
Render object using templated with name
Declaration
Swift
public func render(_ object: Any, withTemplate name: String) -> String?
Parameters
object
Object to render
name
Name of template
Return Value
Rendered text
-
Error returned by init() when parser fails
See moreDeclaration
Swift
public struct ParserError : Swift.Error
-
Load templates from a folder
Declaration
Swift
func loadTemplates(from directory: String, withExtension extension: String = "mustache") throws