refactor: TemplateLoader to protocol, follow Swift API guidelines

This commit is contained in:
Kyle Fuller
2016-11-28 03:50:53 +00:00
parent 5ca1b78854
commit 429290e0b7
9 changed files with 65 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ import PathKit
func testInclude() {
describe("Include") {
let path = Path(#file) + ".." + "fixtures"
let loader = TemplateLoader(paths: [path])
let loader = FileSystemLoader(paths: [path])
$0.describe("parsing") {
$0.it("throws an error when no template is given") {

View File

@@ -6,17 +6,17 @@ import PathKit
func testInheritence() {
describe("Inheritence") {
let path = Path(#file) + ".." + "fixtures"
let loader = TemplateLoader(paths: [path])
let loader = FileSystemLoader(paths: [path])
$0.it("can inherit from another template") {
let context = Context(dictionary: ["loader": loader])
let template = loader.loadTemplate("child.html")
let template = try loader.loadTemplate(name: "child.html")
try expect(try template?.render(context)) == "Header\nChild"
}
$0.it("can inherit from another template inheriting from another template") {
let context = Context(dictionary: ["loader": loader])
let template = loader.loadTemplate("child-child.html")
let template = try loader.loadTemplate(name: "child-child.html")
try expect(try template?.render(context)) == "Child Child Header\nChild"
}
}

View File

@@ -6,18 +6,18 @@ import PathKit
func testTemplateLoader() {
describe("TemplateLoader") {
let path = Path(#file) + ".." + "fixtures"
let loader = TemplateLoader(paths: [path])
let loader = FileSystemLoader(paths: [path])
$0.it("returns nil when a template cannot be found") {
try expect(loader.loadTemplate("unknown.html")).to.beNil()
try expect(try loader.loadTemplate(name: "unknown.html")).to.beNil()
}
$0.it("returns nil when an array of templates cannot be found") {
try expect(loader.loadTemplate(["unknown.html", "unknown2.html"])).to.beNil()
try expect(try loader.loadTemplate(names: ["unknown.html", "unknown2.html"])).to.beNil()
}
$0.it("can load a template from a file") {
if loader.loadTemplate("test.html") == nil {
if try loader.loadTemplate(name: "test.html") == nil {
throw failure("didn't find the template")
}
}