feat: Creating of templates from a string literal (#71)

This commit is contained in:
Valentin Knabel
2016-10-11 13:45:15 +02:00
committed by Kyle Fuller
parent 65c3052aee
commit 68e6ce3022
2 changed files with 23 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ let NSFileNoSuchFileError = 4
#endif
/// A class representing a template
open class Template {
open class Template: ExpressibleByStringLiteral {
let tokens: [Token]
/// Create a template with the given name inside the given bundle
@@ -35,6 +35,21 @@ open class Template {
tokens = lexer.tokenize()
}
// Create a template with a template string literal
public convenience required init(stringLiteral value:String) {
self.init(templateString: value)
}
// Create a template with a template string literal
public convenience required init(extendedGraphemeClusterLiteral value:StringLiteralType) {
self.init(stringLiteral: value)
}
// Create a template with a template string literal
public convenience required init(unicodeScalarLiteral value:StringLiteralType) {
self.init(stringLiteral: value)
}
/// Render the given template
open func render(_ context: Context? = nil) throws -> String {
let context = context ?? Context()