Allow template filters to throw errors

This commit is contained in:
Kyle Fuller
2015-10-24 14:41:37 -07:00
parent f35be4b701
commit 8ac6e26876
5 changed files with 29 additions and 20 deletions

View File

@@ -4,9 +4,9 @@ import Stencil
describe("template filters") {
let context = Context(dictionary: ["name": "Kyle"])
let template = Template(templateString: "{{ name|repeat }}")
$0.it("allows you to register a custom filter") {
let template = Template(templateString: "{{ name|repeat }}")
template.parser.registerFilter("repeat") { value in
if let value = value as? String {
return "\(value) \(value)"
@@ -18,6 +18,15 @@ describe("template filters") {
let result = try template.render(context)
try expect(result) == "Kyle Kyle"
}
$0.it("allows you to register a custom filter") {
let template = Template(templateString: "{{ name|repeat }}")
template.parser.registerFilter("repeat") { value in
throw TemplateSyntaxError("No Repeat")
}
try expect(try template.render(context)).toThrow(TemplateSyntaxError("No Repeat"))
}
}