Switch to Conche and Spectre

This commit is contained in:
Kyle Fuller
2015-10-22 11:49:32 -07:00
parent 6464b3170a
commit d5acc7298c
36 changed files with 577 additions and 1492 deletions

View File

@@ -0,0 +1,61 @@
import Spectre
import Stencil
class CustomNode : NodeType {
func render(context:Context) throws -> String {
return "Hello World"
}
}
describe("Stencil") {
$0.it("can render the README example") {
let templateString = "There are {{ articles.count }} articles.\n" +
"\n" +
"{% for article in articles %}" +
" - {{ article.title }} by {{ article.author }}.\n" +
"{% endfor %}\n"
let context = Context(dictionary: [
"articles": [
[ "title": "Migrating from OCUnit to XCTest", "author": "Kyle Fuller" ],
[ "title": "Memory Management with ARC", "author": "Kyle Fuller" ],
]
])
let template = Template(templateString:templateString)
let result = try template.render(context)
let fixture = "There are 2 articles.\n" +
"\n" +
" - Migrating from OCUnit to XCTest by Kyle Fuller.\n" +
" - Memory Management with ARC by Kyle Fuller.\n" +
"\n"
try expect(result) == fixture
}
$0.it("can render a custom template tag") {
let templateString = "{% custom %}"
let template = Template(templateString:templateString)
template.parser.registerTag("custom") { parser, token in
return CustomNode()
}
let result = try template.render()
try expect(result) == "Hello World"
}
$0.it("can render a simple custom tag") {
let templateString = "{% custom %}"
let template = Template(templateString:templateString)
template.parser.registerSimpleTag("custom") { context in
return "Hello World"
}
try expect(try template.render()) == "Hello World"
}
}