Add swift-log so we can log loading errors
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import Foundation
|
||||
import Logging
|
||||
|
||||
extension HBMustacheLibrary {
|
||||
/// Load templates from a folder
|
||||
func loadTemplates(from directory: String, withExtension extension: String = "mustache") {
|
||||
func loadTemplates(from directory: String, withExtension extension: String = "mustache", logger: Logger?) {
|
||||
var directory = directory
|
||||
if !directory.hasSuffix("/") {
|
||||
directory += "/"
|
||||
@@ -14,8 +15,11 @@ extension HBMustacheLibrary {
|
||||
guard path.hasSuffix(extWithDot) else { continue }
|
||||
guard let data = fs.contents(atPath: directory + path) else { continue}
|
||||
let string = String(decoding: data, as: Unicode.UTF8.self)
|
||||
guard let template = try? HBMustacheTemplate(string: string) else { continue }
|
||||
|
||||
guard let template = try? HBMustacheTemplate(string: string) else {
|
||||
logger?.error("Failed to load \(path)")
|
||||
continue
|
||||
}
|
||||
logger?.debug("Loading \(path)")
|
||||
// drop ".mustache" from path to get name
|
||||
let name = String(path.dropLast(extWithDot.count))
|
||||
register(template, named: name)
|
||||
|
||||
Reference in New Issue
Block a user