feat: Creating of templates from a string literal (#71)
This commit is contained in:
committed by
Kyle Fuller
parent
65c3052aee
commit
68e6ce3022
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user