From 3ce936383764d4f6226ac38e512843efcea542f5 Mon Sep 17 00:00:00 2001 From: Dan Appel Date: Sat, 12 Nov 2016 15:16:22 -0800 Subject: [PATCH] Simplify TemplateCollection API (only one path parameter) --- Sources/TemplateCollection.swift | 9 ++++----- .../MuttonChopTests/TemplateCollectionTests.swift | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/TemplateCollection.swift b/Sources/TemplateCollection.swift index abd2ee5..7689a53 100644 --- a/Sources/TemplateCollection.swift +++ b/Sources/TemplateCollection.swift @@ -24,17 +24,16 @@ public struct TemplateCollection { // MARK: IO import Foundation extension TemplateCollection { - public init(basePath: String = FileManager.default.currentDirectoryPath, directory: String, fileExtensions: [String] = ["mustache"]) throws { - let path = basePath + directory - let files = try FileManager.default.contentsOfDirectory(atPath: path) + public init(directory: String, fileExtensions: [String] = ["mustache"]) throws { + let files = try FileManager.default.contentsOfDirectory(atPath: directory) .map { NSString(string: $0) } var templates = [String: Template]() for file in files where fileExtensions.contains(file.pathExtension) { - + let path = NSString(string: directory).appendingPathComponent(String(file)) guard - let handle = FileHandle(forReadingAtPath: "\(path)/\(file)"), + let handle = FileHandle(forReadingAtPath: path), let contents = String(data: handle.readDataToEndOfFile(), encoding: .utf8) else { continue diff --git a/Tests/MuttonChopTests/MuttonChopTests/TemplateCollectionTests.swift b/Tests/MuttonChopTests/MuttonChopTests/TemplateCollectionTests.swift index 05b60c3..34775dd 100644 --- a/Tests/MuttonChopTests/MuttonChopTests/TemplateCollectionTests.swift +++ b/Tests/MuttonChopTests/MuttonChopTests/TemplateCollectionTests.swift @@ -42,7 +42,7 @@ class TemplateCollectionTests: XCTestCase { } func testFileCollection() throws { - let collection = try TemplateCollection(basePath: currentDirectory, directory: "Fixtures") + let collection = try TemplateCollection(directory: currentDirectory + "Fixtures") try testGetting(for: collection) try testRendering(for: collection)