@@ -22,11 +22,11 @@ let context = Context(dictionary: [
|
|||||||
]
|
]
|
||||||
])
|
])
|
||||||
|
|
||||||
let template = Template(path:"template.stencil")
|
let template = Template(named: "template.stencil")
|
||||||
let result = template.render(context)
|
let result = template.render(context)
|
||||||
|
|
||||||
if let error = result.error {
|
if let error = result.error {
|
||||||
println("There was a syntax error parsing your template (\(error)).")
|
println("There was an error rendering your template (\(error)).")
|
||||||
}
|
}
|
||||||
|
|
||||||
println("\(result.string)")
|
println("\(result.string)")
|
||||||
|
|||||||
@@ -8,9 +8,31 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct Template {
|
public class Template {
|
||||||
let nodes:[Node]
|
let nodes:[Node]
|
||||||
|
|
||||||
|
public convenience init(named:String) {
|
||||||
|
self.init(named:named, inBundle:nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
public convenience init(named:String, inBundle bundle:NSBundle?) {
|
||||||
|
var url:NSURL?
|
||||||
|
|
||||||
|
if let bundle = bundle {
|
||||||
|
url = bundle.URLForResource(named, withExtension: nil)
|
||||||
|
} else {
|
||||||
|
url = NSBundle.mainBundle().URLForResource(named, withExtension: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.init(URL:url!)
|
||||||
|
}
|
||||||
|
|
||||||
|
public convenience init(URL:NSURL) {
|
||||||
|
var error:NSError?
|
||||||
|
let templateString = NSString.stringWithContentsOfURL(URL, encoding: NSUTF8StringEncoding, error: &error)
|
||||||
|
self.init(templateString:templateString)
|
||||||
|
}
|
||||||
|
|
||||||
public init(templateString:String) {
|
public init(templateString:String) {
|
||||||
let lexer = Lexer(templateString: templateString)
|
let lexer = Lexer(templateString: templateString)
|
||||||
let tokens = lexer.tokenize()
|
let tokens = lexer.tokenize()
|
||||||
|
|||||||
Reference in New Issue
Block a user