Add 'Namespace' a container for tags and filters

This commit is contained in:
Kyle Fuller
2015-11-18 16:08:18 +03:00
parent 226becb258
commit dc774fe43b
11 changed files with 115 additions and 86 deletions

View File

@@ -3,8 +3,7 @@ import PathKit
/// A class representing a template
public class Template {
public let parser:TokenParser
private var nodes:[NodeType]? = nil
let tokens: [Token]
/// Create a template with the given name inside the given bundle
public convenience init(named:String, inBundle bundle:NSBundle? = nil) throws {
@@ -29,16 +28,13 @@ public class Template {
/// Create a template with a template string
public init(templateString:String) {
let lexer = Lexer(templateString: templateString)
let tokens = lexer.tokenize()
parser = TokenParser(tokens: tokens)
tokens = lexer.tokenize()
}
/// Render the given template
public func render(context:Context? = nil) throws -> String {
if nodes == nil {
nodes = try parser.parse()
}
return try renderNodes(nodes!, context ?? Context())
public func render(context: Context? = nil, namespace: Namespace? = nil) throws -> String {
let parser = TokenParser(tokens: tokens, namespace: namespace ?? Namespace())
let nodes = try parser.parse()
return try renderNodes(nodes, context ?? Context())
}
}