Skip to content

Commit

Permalink
Kitura/Kitura#675 unified handling a url in Linux and macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimeisenbergibm committed Aug 15, 2016
1 parent aaeeaee commit 1bc2934
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Sources/Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,11 @@ final public class Template {
- returns: A new Template.
*/
public convenience init(path: String, encoding: String.Encoding = String.Encoding.utf8) throws {
#if os(Linux)
let url = URL(fileURLWithPath: path, isDirectory: false)
let directoryPath = url.URLByDeletingLastPathComponent?.path ?? ""
let templateExtension = url.pathExtension ?? ""
let templateName = url.URLByDeletingPathExtension?.lastPathComponent ?? ""
#else
let nsPath = path.bridge()
let directoryPath = nsPath.deletingLastPathComponent
let templateExtension = nsPath.pathExtension
let templateName = nsPath.deletingPathExtension().lastPathComponent
#endif
let url = URL(fileURLWithPath: path, isDirectory: false)
let directoryPath = url.deletingLastPathComponent()
let templateExtension = url.pathExtension
let templateName = url.deletingPathExtension().lastPathComponent

let repository = TemplateRepository(directoryPath: directoryPath, templateExtension: templateExtension, encoding: encoding)
let templateAST = try repository.templateAST(named: templateName)
self.init(repository: repository, templateAST: templateAST, baseContext: repository.configuration.baseContext)
Expand Down

0 comments on commit 1bc2934

Please sign in to comment.