Skip to content

Commit

Permalink
[helpers] Added more helper functions and removed the Vapor dependenc…
Browse files Browse the repository at this point in the history
…y in order to support multiple providers
  • Loading branch information
MatsMoll committed Dec 27, 2019
1 parent 15d96f6 commit aa81be2
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 269 deletions.
153 changes: 0 additions & 153 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
{
"object": {
"pins": [
{
"package": "Console",
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "74cfbea629d4aac34a97cead2447a6870af1950b",
"version": "3.1.1"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "10d33362a47fab03a067e78fb0791341d9c634fa",
"version": "3.9.3"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "df8eb7d8ae51787b3a0628aa3975e67666da936c",
"version": "3.3.3"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "8f352c8e66dab301ab9bfef912a01ce1361ba1e4",
"version": "1.3.3"
}
},
{
"package": "HTTP",
"repositoryURL": "https://github.com/vapor/http.git",
"state": {
"branch": null,
"revision": "3808ed0401379b6e9f4a053f03090ea9d658caa9",
"version": "3.2.1"
}
},
{
"package": "Lingo",
"repositoryURL": "https://github.com/miroslavkovac/Lingo.git",
Expand All @@ -54,114 +9,6 @@
"revision": "f21f388b04239641b3e88d14f21762125faa9857",
"version": "3.0.5"
}
},
{
"package": "Multipart",
"repositoryURL": "https://github.com/vapor/multipart.git",
"state": {
"branch": null,
"revision": "f063180d0b84832accd33194e06ed3c41f8609ac",
"version": "3.1.1"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
"state": {
"branch": null,
"revision": "d76f339c9716785e5079af9d7075d28ff7da3d92",
"version": "3.1.0"
}
},
{
"package": "Service",
"repositoryURL": "https://github.com/vapor/service.git",
"state": {
"branch": null,
"revision": "fa5b5de62bd68bcde9a69933f31319e46c7275fb",
"version": "1.0.2"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd",
"version": "1.14.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "0f3999f3e3c359cc74480c292644c3419e44a12f",
"version": "1.4.0"
}
},
{
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
}
},
{
"package": "TemplateKit",
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "51405c83e95e8adb09565278a5e9b959c605e56c",
"version": "1.4.0"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "82d8d63bdb76b6dd8febe916c639ab8608dbbaed",
"version": "1.0.6"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
"state": {
"branch": null,
"revision": "4de213cf319b694e4ce19e5339592601d4dd3ff6",
"version": "2.1.1"
}
},
{
"package": "Vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "92a58a9a84e4330500b99fe355a94d29f67abe58",
"version": "3.3.1"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/vapor/websocket.git",
"state": {
"branch": null,
"revision": "d85e5b6dce4d04065865f77385fc3324f98178f6",
"version": "1.1.2"
}
}
]
},
Expand Down
9 changes: 1 addition & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "HTMLKit",
targets: ["HTMLKit"]),
.library(
name: "HTMLKitVapor",
targets: ["HTMLKitVapor"]),
targets: ["HTMLKit"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),

.package(url: "https://github.com/miroslavkovac/Lingo.git", from: "3.0.5"),
// .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")),
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "HTMLKit",
dependencies: ["Lingo"]),
.target(
name: "HTMLKitVapor",
dependencies: ["HTMLKit", "Vapor"]),
.testTarget(
name: "HTMLKitTests",
dependencies: ["HTMLKit"]),
Expand Down
9 changes: 9 additions & 0 deletions Sources/HTMLKit/TemplateValue.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

import Foundation

@propertyWrapper
@dynamicMemberLookup
public enum TemplateValue<Root, Value> {
case constant(Value)
case dynamic(ContextVariable<Root, Value>)

public var wrappedValue: TemplateValue { self }

public subscript<Subject>(dynamicMember keyPath: KeyPath<Value, Subject>) -> TemplateValue<Root, Subject> {
switch self {
case .constant(let value): return .constant(value[keyPath: keyPath])
Expand Down Expand Up @@ -71,6 +74,12 @@ extension TemplateValue where Value == String, Root == Void {
}
}

extension TemplateValue where Root == Value {
public init(_ root: Root.Type) {
self = .root()
}
}

extension TemplateValue {
public static func root<T>() -> TemplateValue<T, T> {
.dynamic(.root())
Expand Down
17 changes: 17 additions & 0 deletions Sources/HTMLKit/Unwrap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

public struct Unwrap<A, B>: HTMLComponent {

let isDefined: Conditionable
let content: HTML

public init(_ value: TemplateValue<A, B?>, @HTMLBuilder content: (TemplateValue<A, B>) -> HTML) {
self.isDefined = value.isDefined
self.content = content(value.unsafelyUnwrapped)
}

public var body: HTML {
IF(isDefined) {
content
}
}
}
105 changes: 0 additions & 105 deletions Sources/HTMLKitVapor/HTMLRenderable+Vapor.swift

This file was deleted.

29 changes: 29 additions & 0 deletions Tests/HTMLKitTests/HTMLKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ final class HTMLKitTests: XCTestCase {
// _ = try! renderer.render(raw: OptionalDateView.self, with: testDate)
// }
// }
// }

// func testView() {
// let formula = HTMLRenderer.Formula()
// try! Test().prerender(formula)
// let context = Test.Context(
// header: true,
// links: [
// MenuLink(name: "WELKOM", link: "index.html"),
// MenuLink(name: "WIE WIJ ZIJN", link: "overons.html"),
// MenuLink(name: "WAT WIJ DOEN", link: "watwijdoen.html"),
// MenuLink(name: "CONTACT", link: "contact.html")
// ],
// text: """
// asf;jadgkhjefaldskfdghfiehjsgdfkgh
// fhsfhjksflhjfslkghjfslkgjsfklgjfslkgjsfgkljdfsgklsdj
// """
// )
// var isFirst = true
//
// measure {
// for _ in 0...10_000 {
// let output = try! formula.render(with: context, lingo: nil)
// if isFirst {
// print(output)
// isFirst = false
// }
// }
// }
// }

func testHtmlRenderingTests() throws {
Expand Down
Loading

0 comments on commit aa81be2

Please sign in to comment.