Files
swiftpm-mustache/Sources/Mustache/Template+FileSystem.swift
Adam Fowler 933fa3d60f Add support for proper lambdas (#48)
* Add support for proper lambdas

* Get rid of recursion

Remove renderSectionLambda as I can use renderUnescapedLambda for that.
2024-09-19 17:17:50 +01:00

33 lines
1.1 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2024 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
extension MustacheTemplate {
/// Internal function to load a template from a file
/// - Parameters
/// - string: Template text
/// - filename: File template was loaded from
/// - Throws: MustacheTemplate.Error
init?(filename: String) throws {
let fs = FileManager()
guard let data = fs.contents(atPath: filename) else { return nil }
let string = String(decoding: data, as: Unicode.UTF8.self)
let template = try Self.parse(string)
self.tokens = template.tokens
self.text = string
self.filename = filename
}
}