Add Package.swift and move files around

This commit is contained in:
Boris Bügling
2015-12-08 11:45:03 +01:00
parent 0bfd4134f9
commit 372b2e7576
35 changed files with 22 additions and 11 deletions

View File

@@ -0,0 +1,38 @@
import Foundation
import PathKit
// A class for loading a template from disk
public class TemplateLoader {
public let paths: [Path]
public init(paths: [Path]) {
self.paths = paths
}
public init(bundle: [NSBundle]) {
self.paths = bundle.map {
return Path($0.bundlePath)
}
}
public func loadTemplate(templateName: String) -> Template? {
return loadTemplate([templateName])
}
public func loadTemplate(templateNames: [String]) -> Template? {
for path in paths {
for templateName in templateNames {
let templatePath = path + Path(templateName)
if templatePath.exists {
if let template = try? Template(path: templatePath) {
return template
}
}
}
}
return nil
}
}