Skip to content

Commit

Permalink
Simplify TemplateCollection API (only one path parameter)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danappelxx committed Nov 15, 2016
1 parent 4bcf9cd commit 3ce9363
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions Sources/TemplateCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ce9363

Please sign in to comment.