Use enum instead of pair as result type for Template

This commit is contained in:
Marius Rackwitz
2014-10-26 13:24:50 +00:00
parent 7b89c32295
commit 25b86dea93
6 changed files with 53 additions and 17 deletions

View File

@@ -44,15 +44,19 @@ public class Template {
parser = TokenParser(tokens: tokens)
}
public func render(context:Context) -> (string:String?, error:Error?) {
public func render(context:Context) -> Result {
let (nodes, error) = parser.parse()
if let error = error {
return (nil, error)
return .Error(error: error)
} else if let nodes = nodes {
return renderNodes(nodes, context)
let result = renderNodes(nodes, context)
if let string = result.0 {
return .Success(string: string)
} else {
return .Error(error: result.1!)
}
}
return (nil, nil)
return .Success(string: "")
}
}