0001 import Foundation 0002 import PathKit 0003 0004 #if os(Linux) 0005 let NSFileNoSuchFileError = 4 0006 #endif 0007 0008 /// A class representing a template 0009 public class Template{ 0010 let tokens
TemplateLoader.swift:19 public func loadTemplate(templateName: String) -> Template? {TemplateLoader.swift:23 public func loadTemplate(templateNames: [String]) -> Template? {: [Token] 0011 0012 /// Create a template with the given name inside the given bundle 0013 public convenience init(named:String, inBundle bundle:NSBundle? = nil) throws { 0014 let useBundle = bundle ?? NSBundle.mainBundle() 0015 guard let url = useBundle.URLForResource(named, withExtension: nil) else { 0016 throw NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError, userInfo: nil) 0017 } 0018 0019 try self.init(URL:url) 0020 } 0021 0022 /// Create a template with a file found at the given URL 0023 public convenience init(URL:NSURL) throws { 0024 try self.init(path: Path(URL.path!)) 0025 } 0026 0027 /// Create a template with a file found at the given path 0028 public convenience init(path:Path) throws { 0029 self.init(templateString: try path.read()) 0030 } 0031 0032 /// Create a template with a template string 0033 public init(templateString:String) { 0034 let lexer = Lexer(templateString: templateString) 0035 tokens = lexer.tokenize() 0036 } 0037 0038 /// Render the given template 0039 public func render
Template.swift:35 tokens = lexer.tokenize()Template.swift:40 let parser = TokenParser(tokens: tokens, namespace: namespace ?? Namespace())(context: Context? = nil, namespace: Namespace? = nil) throws -> String { 0040 let parser = TokenParser(tokens: tokens, namespace: namespace ?? Namespace()) 0041 let nodes = try parser.parse() 0042 return try renderNodes(nodes, context ?? Context()) 0043 } 0044 } 0045
Include.swift:35 return try template.render(context)Inheritence.swift:78 let result = try template.render(context)