Skip to content

Commit

Permalink
LeafKit 1.0.0.tau (#178)
Browse files Browse the repository at this point in the history
Leaf 4.0.0-tau

tau is the final prerelease of LeafKit 1.0 and Leaf4.

This is a massive rebuild from the previous prerelease version and entirely replaces the architecture for extending the language; as such, there is no direct transition path for converting LeafTag objects to the new architecture directly.

Migration documents are coming soon to address how that functionality has improved and changed.
  • Loading branch information
tdotclare authored Nov 1, 2020
1 parent 63b5d96 commit a8348b6
Show file tree
Hide file tree
Showing 24 changed files with 745 additions and 542 deletions.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "Leaf", targets: ["Leaf"]),
],
dependencies: [
.package(url: "https://github.com/vapor/leaf-kit.git", from: "1.0.0-rc.1.16"),
.package(name: "leaf-kit", url: "https://github.com/vapor/leaf-kit", from: "1.0.0-tau.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
Expand All @@ -21,6 +21,7 @@ let package = Package(
.testTarget(name: "LeafTests", dependencies: [
.target(name: "Leaf"),
.product(name: "XCTVapor", package: "vapor"),
.product(name: "XCTLeafKit", package: "leaf-kit")
]),
]
)
120 changes: 0 additions & 120 deletions Sources/Leaf/Application+Leaf.swift

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/Leaf/Deprecated.swift

This file was deleted.

24 changes: 24 additions & 0 deletions Sources/Leaf/Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Vapor

internal typealias ELF = EventLoopFuture
internal typealias LFMIndexing = LeafFileMiddleware.DirectoryIndexing
internal typealias Record = (process: Bool, modTime: Date)

internal extension Request {
var eL: EventLoop { eventLoop }
func fail<T>(_ error: Error) -> ELF<T> { eL.makeFailedFuture(error) }
func succeed<T>(_ value: T) -> ELF<T> { eL.makeSucceededFuture(value) }
}

internal extension LeafEngine {
var eL: EventLoop { eventLoop }
func fail<T>(_ error: Error) -> ELF<T> { eL.makeFailedFuture(error) }
func succeed<T>(_ value: T) -> ELF<T> { eL.makeSucceededFuture(value) }
}

internal extension String {
var fileExt: String {
if let i = lastIndex(of: ".") { return String(self[index(after: i)..<endIndex]) }
return ""
}
}
26 changes: 26 additions & 0 deletions Sources/Leaf/LeafDataRepresentable/Foundation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import Vapor

extension URL {
var _leafData: LeafData {
var values = (try? resourceValues(forKeys: .init(LFMIndexing.keys)))?._leafData ?? [:]
values["name"] = lastPathComponent
values["absolutePath"] = absoluteString
values["pathComponents"] = pathComponents
values["mimeType"] = HTTPMediaType.fileExtension(pathExtension) ?? .plainText
return .dictionary(values)
}
}

extension URLResourceValues {
var _leafData: [String: LeafDataRepresentable] {[
"isApplication": isApplication,
"isDirectory": isDirectory,
"isRegularFile": isRegularFile,
"isHidden": isHidden,
"isSymbolicLink": isSymbolicLink,
"fileSize": fileSize,
"creationDate": creationDate, // returns nil on Ubuntu xenial
"contentModificationDate": contentModificationDate,
]}
}
11 changes: 11 additions & 0 deletions Sources/Leaf/LeafDataRepresentable/Vapor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Vapor

extension HTTPMediaType: LeafDataRepresentable {
public static var leafDataType: LeafDataType? { .dictionary }
public var leafData: LeafData { .dictionary([
"type": type,
"subType": subType,
"parameters": parameters,
"serialized": serialize(),
]) }
}
Loading

0 comments on commit a8348b6

Please sign in to comment.