Skip to content

Commit 80c4453

Browse files
committed
Revert "LeafKit 1.0.0.tau (#178)"
This reverts commit a8348b6.
1 parent a8348b6 commit 80c4453

24 files changed

+542
-745
lines changed

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(name: "Leaf", targets: ["Leaf"]),
1111
],
1212
dependencies: [
13-
.package(name: "leaf-kit", url: "https://github.com/vapor/leaf-kit", from: "1.0.0-tau.1"),
13+
.package(url: "https://github.com/vapor/leaf-kit.git", from: "1.0.0-rc.1.16"),
1414
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
1515
],
1616
targets: [
@@ -21,7 +21,6 @@ let package = Package(
2121
.testTarget(name: "LeafTests", dependencies: [
2222
.target(name: "Leaf"),
2323
.product(name: "XCTVapor", package: "vapor"),
24-
.product(name: "XCTLeafKit", package: "leaf-kit")
2524
]),
2625
]
2726
)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import Vapor
2+
3+
extension Application.Views.Provider {
4+
public static var leaf: Self {
5+
.init {
6+
$0.views.use {
7+
$0.leaf.renderer
8+
}
9+
}
10+
}
11+
}
12+
13+
extension Application {
14+
public var leaf: Leaf {
15+
.init(application: self)
16+
}
17+
18+
public struct Leaf {
19+
public let application: Application
20+
21+
public var renderer: LeafRenderer {
22+
var userInfo = self.userInfo
23+
userInfo["application"] = self
24+
25+
return .init(
26+
configuration: self.configuration,
27+
cache: self.cache,
28+
sources: self.sources,
29+
eventLoop: self.application.eventLoopGroup.next(),
30+
userInfo: userInfo
31+
)
32+
}
33+
34+
public var configuration: LeafConfiguration {
35+
get {
36+
self.storage.configuration ?? LeafConfiguration(
37+
rootDirectory: self.application.directory.viewsDirectory
38+
)
39+
}
40+
nonmutating set {
41+
self.storage.configuration = newValue
42+
}
43+
}
44+
45+
public var tags: [String: LeafTag] {
46+
get {
47+
self.storage.tags
48+
}
49+
nonmutating set {
50+
self.storage.tags = newValue
51+
}
52+
}
53+
54+
public var sources: LeafSources {
55+
get {
56+
self.storage.sources ?? LeafSources.singleSource(
57+
NIOLeafFiles(fileio: self.application.fileio,
58+
limits: .default,
59+
sandboxDirectory: self.configuration.rootDirectory,
60+
viewDirectory: self.configuration.rootDirectory))
61+
}
62+
nonmutating set {
63+
self.storage.sources = newValue
64+
}
65+
}
66+
67+
public var cache: LeafCache {
68+
get {
69+
self.storage.cache
70+
}
71+
nonmutating set {
72+
self.storage.cache = newValue
73+
}
74+
}
75+
76+
public var userInfo: [AnyHashable: Any] {
77+
get {
78+
self.storage.userInfo
79+
}
80+
nonmutating set {
81+
self.storage.userInfo = newValue
82+
}
83+
}
84+
85+
var storage: Storage {
86+
if let existing = self.application.storage[Key.self] {
87+
return existing
88+
} else {
89+
let new = Storage()
90+
self.application.storage[Key.self] = new
91+
return new
92+
}
93+
}
94+
95+
struct Key: StorageKey {
96+
typealias Value = Storage
97+
}
98+
99+
final class Storage {
100+
var cache: LeafCache
101+
var configuration: LeafConfiguration?
102+
var sources: LeafSources?
103+
var tags: [String: LeafTag]
104+
var userInfo: [AnyHashable: Any]
105+
106+
init() {
107+
self.cache = DefaultLeafCache()
108+
self.tags = LeafKit.defaultTags
109+
self.userInfo = [:]
110+
}
111+
}
112+
}
113+
}
114+
115+
116+
extension LeafContext {
117+
public var application: Application? {
118+
self.userInfo["application"] as? Application
119+
}
120+
}

Sources/Leaf/Deprecated.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Vapor
2+
3+
4+
extension Application.Leaf {
5+
/// Deprecated in Leaf-Kit 1.0.0rc-1.??
6+
@available(*, deprecated, message: "Use .sources instead of .files")
7+
public var files: LeafSource {
8+
get {
9+
fatalError("Unavailable")
10+
}
11+
nonmutating set {
12+
self.storage.sources = .singleSource(newValue)
13+
}
14+
}
15+
}

Sources/Leaf/Helpers.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/Leaf/LeafDataRepresentable/Foundation.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

Sources/Leaf/LeafDataRepresentable/Vapor.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)