Skip to content

Commit 3f46028

Browse files
authored
Merge pull request #146 from vapor/tn-beta-2
beta 2 updates
2 parents 11ab61c + 7cdb42d commit 3f46028

File tree

7 files changed

+73
-79
lines changed

7 files changed

+73
-79
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [tanner0101]
2+
open_collective: vapor

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: test
2+
on:
3+
- pull_request
4+
jobs:
5+
xenial:
6+
container:
7+
image: vapor/swift:5.1-xenial
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v1
11+
- run: swift test --enable-test-discovery
12+
bionic:
13+
container:
14+
image: vapor/swift:5.1-bionic
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v1
18+
- run: swift test --enable-test-discovery
19+
thread:
20+
container:
21+
image: vapor/swift:5.1-bionic
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v1
25+
- run: swift test --enable-test-discovery --sanitize=thread

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ let package = Package(
1010
.library(name: "Leaf", targets: ["Leaf"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/vapor/leaf-kit.git", from: "1.0.0-alpha"),
14-
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-alpha"),
13+
.package(url: "https://github.com/vapor/leaf-kit.git", .branch("master")),
14+
.package(url: "https://github.com/vapor/vapor.git", .branch("master")),
1515
],
1616
targets: [
1717
.target(name: "Leaf", dependencies: ["LeafKit", "Vapor"]),

Sources/Leaf/LeafProvider.swift

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
import Vapor
22

3-
public final class LeafProvider: Provider {
4-
public init() { }
3+
public final class Leaf: Provider {
4+
public let application: Application
5+
public var cache: LeafCache
6+
7+
public var renderer: LeafRenderer {
8+
.init(
9+
configuration: .init(
10+
rootDirectory: self.application.directory.viewsDirectory
11+
),
12+
cache: self.cache,
13+
fileio: self.application.fileio,
14+
eventLoop: self.application.eventLoopGroup.next()
15+
)
16+
}
17+
18+
public init(_ application: Application) {
19+
self.application = application
20+
self.cache = DefaultLeafCache()
21+
}
522

623
public func register(_ app: Application) {
7-
app.register(LeafRenderer.self) { app in
8-
LeafRenderer(
9-
config: app.make(),
10-
threadPool: app.make(),
11-
eventLoop: app.make()
12-
)
13-
}
24+
app.views.use { self.renderer }
25+
}
26+
}
1427

15-
app.register(ViewRenderer.self) { app in
16-
app.make(LeafRenderer.self)
17-
}
28+
extension Request {
29+
var leaf: LeafRenderer {
30+
.init(
31+
configuration: .init(rootDirectory: self.application.directory.viewsDirectory),
32+
cache: self.application.leaf.cache,
33+
fileio: self.application.fileio,
34+
eventLoop: self.eventLoop
35+
)
36+
}
37+
}
1838

19-
app.register(LeafConfig.self) { app in
20-
let directory = app.make(DirectoryConfiguration.self)
21-
return LeafConfig(rootDirectory: directory.viewsDirectory)
22-
}
39+
extension Application {
40+
public var leaf: Leaf {
41+
self.providers.require(Leaf.self)
2342
}
2443
}
2544

2645
extension LeafRenderer: ViewRenderer {
46+
public func `for`(_ request: Request) -> ViewRenderer {
47+
LeafRenderer(
48+
configuration: self.configuration,
49+
cache: self.cache,
50+
fileio: self.fileio,
51+
eventLoop: request.eventLoop
52+
)
53+
}
54+
2755
public func render<E>(_ name: String, _ context: E) -> EventLoopFuture<View>
2856
where E: Encodable
2957
{
@@ -38,13 +66,3 @@ extension LeafRenderer: ViewRenderer {
3866
}
3967
}
4068
}
41-
42-
extension Request {
43-
public var leaf: LeafRenderer {
44-
LeafRenderer(
45-
config: self.application.make(),
46-
threadPool: self.application.make(),
47-
eventLoop: self.eventLoop
48-
)
49-
}
50-
}

Tests/LeafTests/XCTestManifests.swift

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

Tests/LinuxMain.swift

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

circle.yml

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

0 commit comments

Comments
 (0)