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

@@ -38,24 +38,26 @@ describe("Stencil") {
$0.it("can render a custom template tag") {
let templateString = "{% custom %}"
let template = Template(templateString:templateString)
let template = Template(templateString: templateString)
template.parser.registerTag("custom") { parser, token in
let namespace = Namespace()
namespace.registerTag("custom") { parser, token in
return CustomNode()
}
let result = try template.render()
let result = try template.render(namespace: namespace)
try expect(result) == "Hello World"
}
$0.it("can render a simple custom tag") {
let templateString = "{% custom %}"
let template = Template(templateString:templateString)
let template = Template(templateString: templateString)
template.parser.registerSimpleTag("custom") { context in
let namespace = Namespace()
namespace.registerSimpleTag("custom") { context in
return "Hello World"
}
try expect(try template.render()) == "Hello World"
try expect(try template.render(namespace: namespace)) == "Hello World"
}
}