From f64100abb234573e372321308c205bb35eb5d331 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 2 Jan 2018 14:03:49 +0000 Subject: [PATCH 01/17] Make it at least compile --- .swift-version | 1 - .travis.yml | 7 --- Package.swift | 15 ++++-- Package@swift-4.swift | 19 -------- Sources/MarkdownProvider/Provider.swift | 32 ++++++++----- Sources/MarkdownProvider/Tag.swift | 63 ++++++++++++++----------- 6 files changed, 68 insertions(+), 69 deletions(-) delete mode 100644 .swift-version delete mode 100644 Package@swift-4.swift diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 8c50098..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -3.1 diff --git a/.travis.yml b/.travis.yml index 87e058b..be64146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,13 +19,6 @@ script: - swift build - swift build -c release - swift test - - if [ $TRAVIS_OS_NAME != "osx" ]; then - sudo apt-get remove vapor; - sudo apt-get install swift=3.1.1; - swift build; - swift build -c release; - swift test; - fi after_success: - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/swift-4-codecov/codecov-swift4)" diff --git a/Package.swift b/Package.swift index b72764e..723d313 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,19 @@ +// swift-tools-version:4.0 + import PackageDescription let package = Package( name: "MarkdownProvider", + products: [ + .library(name: "MarkdownProvider", targets: ["MarkdownProvider"]), + ], dependencies: [ - .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2), - .Package(url: "https://github.com/vapor/leaf-provider.git", majorVersion: 1), - .Package(url: "https://github.com/vapor-community/markdown.git", majorVersion: 0) + .package(url: "https://github.com/vapor/vapor.git", .branch("beta")), + .package(url: "https://github.com/vapor/leaf.git", .branch("beta")), + .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), + ], + targets: [ + .target(name: "MarkdownProvider", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), + .testTarget(name: "MarkdownProviderTests", dependencies: ["MarkdownProvider"]), ] ) diff --git a/Package@swift-4.swift b/Package@swift-4.swift deleted file mode 100644 index 383d279..0000000 --- a/Package@swift-4.swift +++ /dev/null @@ -1,19 +0,0 @@ -// swift-tools-version:4.0 - -import PackageDescription - -let package = Package( - name: "MarkdownProvider", - products: [ - .library(name: "MarkdownProvider", targets: ["MarkdownProvider"]), - ], - dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.1.0")), - .package(url: "https://github.com/vapor/leaf-provider.git", .upToNextMajor(from: "1.0.0")), - .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), - ], - targets: [ - .target(name: "MarkdownProvider", dependencies: ["Vapor", "LeafProvider", "SwiftMarkdown"]), - .testTarget(name: "MarkdownProviderTests", dependencies: ["MarkdownProvider"]), - ] -) diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index 7894cbe..35b8a10 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -1,21 +1,29 @@ import Vapor -import LeafProvider +import Leaf public struct Provider: Vapor.Provider { public static let repositoryName = "markdown-provider" - public func boot(_ drop: Droplet) { - guard let renderer = drop.view as? LeafRenderer else { - print("Markdown Provider only supports Leaf as a renderer") - return - } - - renderer.stem.register(Markdown()) + public func register(_ services: inout Services) throws { + } - public init(config: Config) throws {} - public init() {} - public func boot(_ config: Config) throws {} - public func beforeRun(_: Vapor.Droplet) {} + public func boot(_ worker: Container) throws { + + } +// +// public func boot(_ drop: Droplet) { +// guard let renderer = drop.view as? LeafRenderer else { +// print("Markdown Provider only supports Leaf as a renderer") +// return +// } +// +// renderer.stem.register(Markdown()) +// } +// +// public init(config: Config) throws {} +// public init() {} +// public func boot(_ config: Config) throws {} +// public func beforeRun(_: Vapor.Droplet) {} } diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/MarkdownProvider/Tag.swift index 1ae7e2f..83d51b0 100644 --- a/Sources/MarkdownProvider/Tag.swift +++ b/Sources/MarkdownProvider/Tag.swift @@ -1,33 +1,42 @@ import Leaf import SwiftMarkdown +import Async -public final class Markdown: Tag { - - public enum Error: Swift.Error { - case invalidArgument(Argument?) - } - - public init() { } - - public let name = "markdown" - - public func shouldRender(stem: Stem, context: Context, tagTemplate: TagTemplate, arguments: [Argument], value: Node?) -> Bool{ - return true - } - - public func run(tagTemplate: TagTemplate, arguments: ArgumentList) throws -> Node? { - var markdown = "" - - if let markdownArgument = arguments.first { - guard let markdownArgumentValue = markdownArgument.string else { - throw Error.invalidArgument(arguments.list.first) - } - markdown = markdownArgumentValue - } - - let markdownHtml = try markdownToHTML(markdown) - let unescaped = markdownHtml.bytes - return .bytes(unescaped) +public final class Markdown: LeafTag { + + public func render(parsed: ParsedTag, context: LeafContext, renderer: LeafRenderer) throws -> Future { + return Future(nil) } + + + + +// public enum Error: Swift.Error { +// case invalidArgument(Argument?) +// } +// +// public init() { } +// +// public let name = "markdown" +// +// public func shouldRender(stem: Stem, context: Context, tagTemplate: TagTemplate, arguments: [Argument], value: Node?) -> Bool{ +// return true +// } +// +// public func run(tagTemplate: TagTemplate, arguments: ArgumentList) throws -> Node? { +// var markdown = "" +// +// if let markdownArgument = arguments.first { +// guard let markdownArgumentValue = markdownArgument.string else { +// throw Error.invalidArgument(arguments.list.first) +// } +// markdown = markdownArgumentValue +// } +// +// let markdownHtml = try markdownToHTML(markdown) +// let unescaped = markdownHtml.bytes +// return .bytes(unescaped) +// } + } From 0f265d24961ea5b8d37be855e6fb4e40dab3334f Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 2 Jan 2018 15:11:25 +0000 Subject: [PATCH 02/17] Test compiling for Vapor 3 --- Sources/MarkdownProvider/Provider.swift | 2 +- Sources/MarkdownProvider/Tag.swift | 2 + Tests/MarkdownProviderTests/LeafTests.swift | 41 +++++++++---------- .../MarkdownProviderTests/ProviderTests.swift | 28 ++++++------- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index 35b8a10..79b4a6a 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -6,7 +6,7 @@ public struct Provider: Vapor.Provider { public static let repositoryName = "markdown-provider" public func register(_ services: inout Services) throws { - + print("Registered") } public func boot(_ worker: Container) throws { diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/MarkdownProvider/Tag.swift index 83d51b0..1c8b4da 100644 --- a/Sources/MarkdownProvider/Tag.swift +++ b/Sources/MarkdownProvider/Tag.swift @@ -4,6 +4,8 @@ import Async public final class Markdown: LeafTag { + public let name = "markdown" + public func render(parsed: ParsedTag, context: LeafContext, renderer: LeafRenderer) throws -> Future { return Future(nil) } diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index b2e5488..4b63ebe 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -9,15 +9,24 @@ class LeafTests: XCTestCase { ("testRunTag", testRunTag), ("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf), ] + + var renderer: LeafRenderer! + let template = "#markdown(data)" + + override func setUp() { + let queue = DispatchEventLoop(label: "io.brokenhands.markdown-provider.test") + let tag = Markdown() + self.renderer = LeafRenderer(config: LeafConfig(tags: [tag.name: tag]), on: queue) + } func testRunTag() { - let tag = Markdown() let inputMarkdown = "# This is a test\n\nWe have some text in a tag" + let data = LeafData.dictionary(["data": .string(inputMarkdown)]) let expectedHtml = "

This is a test

\n

We have some text in a tag

\n" - + do { - let node = try run(tag: tag, context: inputMarkdown.makeNode(in: nil), arguments: [.constant(Leaf(raw: inputMarkdown, components: [.raw(inputMarkdown.makeBytes())]))]) - XCTAssertEqual(node?.string, expectedHtml) + let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() + XCTAssertEqual(result, expectedHtml) } catch { XCTFail() @@ -25,27 +34,15 @@ class LeafTests: XCTestCase { } func testNilParameterDoesNotCrashLeaf() { - let tag = Markdown() + let data = LeafData.dictionary(["data": .null]) let expectedHtml = "" - + do { - let node = try run(tag: tag, context: nil, arguments: []) - XCTAssertEqual(node?.string, expectedHtml) + let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() + XCTAssertEqual(result, expectedHtml) } - catch { - XCTFail("Markdown Tag threw exception") + catch { + XCTFail() } } } - -extension LeafTests { - func run(tag: Tag, context node: Node, arguments: [Argument]) throws -> Node? { - let context = Context(node) - let argumentList = ArgumentList(list: arguments, stem: Stem(DataFile(workDir: "")), context: context) - - return try tag.run( - tagTemplate: TagTemplate(name: "", parameters: [], body: nil), - arguments: argumentList - ) - } -} diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/MarkdownProviderTests/ProviderTests.swift index 9b1a7c5..8581d2e 100644 --- a/Tests/MarkdownProviderTests/ProviderTests.swift +++ b/Tests/MarkdownProviderTests/ProviderTests.swift @@ -1,6 +1,6 @@ import XCTest import Vapor -import LeafProvider +import Leaf @testable import MarkdownProvider @@ -11,25 +11,21 @@ class ProviderTests: XCTestCase { ] func testProviderAddsTagToLeaf() throws { - var config = Config([:]) - try config.set("droplet.view", "leaf") - try config.addProvider(LeafProvider.Provider.self) - let drop = try Droplet(config) - let leafProvider = MarkdownProvider.Provider() - leafProvider.boot(drop) - - guard let leaf = drop.view as? LeafRenderer else { - XCTFail() - return - } - - XCTAssertNotNil(leaf.stem.tags[Markdown().name]) + var services = Services.default() + let leafProvider = LeafProvider() + services.use(leafProvider) + services.use(MarkdownProvider.Provider.self) + let app = try Application(services: services) + + let renderer = try app.make(LeafRenderer.self, for: ViewRenderer.self) + + XCTAssertNotNil(renderer.tags[Markdown().name]) } func testProviderGracefullyHandlesNonLeafRenderer() throws { - let drop = try Droplet() + let app = try Application() let leafProvider = MarkdownProvider.Provider() - leafProvider.boot(drop) + try leafProvider.boot(app) XCTAssert(true, "We should reach this point") } } From 82f8572ea5914f638810a5adbc0c837258894248 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 2 Jan 2018 15:24:26 +0000 Subject: [PATCH 03/17] Port tag code to Vapor 3 --- Sources/MarkdownProvider/Tag.swift | 45 ++++++++------------- Tests/MarkdownProviderTests/LeafTests.swift | 22 +++------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/MarkdownProvider/Tag.swift index 1c8b4da..9ec67c9 100644 --- a/Sources/MarkdownProvider/Tag.swift +++ b/Sources/MarkdownProvider/Tag.swift @@ -4,41 +4,28 @@ import Async public final class Markdown: LeafTag { + public enum Error: Swift.Error { + case invalidArgument(LeafData?) + } + public let name = "markdown" public func render(parsed: ParsedTag, context: LeafContext, renderer: LeafRenderer) throws -> Future { - return Future(nil) - } + var markdown = "" + if let markdownArgument = parsed.parameters.first, !markdownArgument.isNull { + guard let markdownArgumentValue = markdownArgument.string else { + throw Error.invalidArgument(parsed.parameters.first) + } + markdown = markdownArgumentValue + } + let markdownHtml = try markdownToHTML(markdown) - -// public enum Error: Swift.Error { -// case invalidArgument(Argument?) -// } -// -// public init() { } -// -// public let name = "markdown" -// -// public func shouldRender(stem: Stem, context: Context, tagTemplate: TagTemplate, arguments: [Argument], value: Node?) -> Bool{ -// return true -// } -// -// public func run(tagTemplate: TagTemplate, arguments: ArgumentList) throws -> Node? { -// var markdown = "" -// -// if let markdownArgument = arguments.first { -// guard let markdownArgumentValue = markdownArgument.string else { -// throw Error.invalidArgument(arguments.list.first) -// } -// markdown = markdownArgumentValue -// } -// -// let markdownHtml = try markdownToHTML(markdown) -// let unescaped = markdownHtml.bytes -// return .bytes(unescaped) -// } + let promise = Promise(LeafData?.self) + promise.complete(.string(markdownHtml)) + return promise.future + } } diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index 4b63ebe..16cfabf 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -19,30 +19,20 @@ class LeafTests: XCTestCase { self.renderer = LeafRenderer(config: LeafConfig(tags: [tag.name: tag]), on: queue) } - func testRunTag() { + func testRunTag() throws { let inputMarkdown = "# This is a test\n\nWe have some text in a tag" let data = LeafData.dictionary(["data": .string(inputMarkdown)]) let expectedHtml = "

This is a test

\n

We have some text in a tag

\n" - do { - let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() - XCTAssertEqual(result, expectedHtml) - } - catch { - XCTFail() - } + let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() + XCTAssertEqual(result, expectedHtml) } - func testNilParameterDoesNotCrashLeaf() { + func testNilParameterDoesNotCrashLeaf() throws { let data = LeafData.dictionary(["data": .null]) let expectedHtml = "" - do { - let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() - XCTAssertEqual(result, expectedHtml) - } - catch { - XCTFail() - } + let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() + XCTAssertEqual(result, expectedHtml) } } From 03a25a13ce65523dbe2735f0056d8a5f36f6914c Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 2 Jan 2018 15:31:29 +0000 Subject: [PATCH 04/17] Swiftlint --- .swiftlint.yml | 3 +++ Sources/MarkdownProvider/Provider.swift | 3 ++- Tests/MarkdownProviderTests/LeafTests.swift | 6 +++--- Tests/MarkdownProviderTests/ProviderTests.swift | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..d1f1d28 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,3 @@ +included: + - Sources + - Tests diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index 79b4a6a..331b611 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -10,7 +10,8 @@ public struct Provider: Vapor.Provider { } public func boot(_ worker: Container) throws { - + let renderer = try worker.make(LeafRenderer.self, for: ViewRenderer.self) + renderer.tags } // // public func boot(_ drop: Droplet) { diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index 16cfabf..765befc 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -7,7 +7,7 @@ import Vapor class LeafTests: XCTestCase { static var allTests = [ ("testRunTag", testRunTag), - ("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf), + ("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf) ] var renderer: LeafRenderer! @@ -18,7 +18,7 @@ class LeafTests: XCTestCase { let tag = Markdown() self.renderer = LeafRenderer(config: LeafConfig(tags: [tag.name: tag]), on: queue) } - + func testRunTag() throws { let inputMarkdown = "# This is a test\n\nWe have some text in a tag" let data = LeafData.dictionary(["data": .string(inputMarkdown)]) @@ -27,7 +27,7 @@ class LeafTests: XCTestCase { let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() XCTAssertEqual(result, expectedHtml) } - + func testNilParameterDoesNotCrashLeaf() throws { let data = LeafData.dictionary(["data": .null]) let expectedHtml = "" diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/MarkdownProviderTests/ProviderTests.swift index 8581d2e..a2d75f6 100644 --- a/Tests/MarkdownProviderTests/ProviderTests.swift +++ b/Tests/MarkdownProviderTests/ProviderTests.swift @@ -9,7 +9,7 @@ class ProviderTests: XCTestCase { ("testProviderCreation", testProviderAddsTagToLeaf), ("testProviderGracefullyHandlesNonLeafRenderer", testProviderGracefullyHandlesNonLeafRenderer) ] - + func testProviderAddsTagToLeaf() throws { var services = Services.default() let leafProvider = LeafProvider() @@ -21,7 +21,7 @@ class ProviderTests: XCTestCase { XCTAssertNotNil(renderer.tags[Markdown().name]) } - + func testProviderGracefullyHandlesNonLeafRenderer() throws { let app = try Application() let leafProvider = MarkdownProvider.Provider() From f80b80c416f82143c428e2ea4bd224fa194ba724 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 2 Jan 2018 16:35:13 +0000 Subject: [PATCH 05/17] Update Xcode image for CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be64146..c0aa57a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: generic sudo: required dist: trusty -osx_image: xcode9 +osx_image: xcode9.2 before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install vapor/tap/vapor; From 077eafbebba3b50040e20a200e4e0122fc936439 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 8 Jan 2018 11:53:52 +0000 Subject: [PATCH 06/17] Handle the lack of LeafProvider gracefully --- Sources/MarkdownProvider/Provider.swift | 12 +++++------- Tests/MarkdownProviderTests/ProviderTests.swift | 10 +++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index 331b611..cf2e54e 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -10,8 +10,11 @@ public struct Provider: Vapor.Provider { } public func boot(_ worker: Container) throws { - let renderer = try worker.make(LeafRenderer.self, for: ViewRenderer.self) - renderer.tags + do { + let renderer = try worker.make(LeafRenderer.self, for: ViewRenderer.self) + } catch is ServiceError { + print("Markdown Provider only supports Leaf as a renderer - make sure the Leaf Provider has been registered") + } } // // public func boot(_ drop: Droplet) { @@ -22,9 +25,4 @@ public struct Provider: Vapor.Provider { // // renderer.stem.register(Markdown()) // } -// -// public init(config: Config) throws {} -// public init() {} -// public func boot(_ config: Config) throws {} -// public func beforeRun(_: Vapor.Droplet) {} } diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/MarkdownProviderTests/ProviderTests.swift index a2d75f6..e70b060 100644 --- a/Tests/MarkdownProviderTests/ProviderTests.swift +++ b/Tests/MarkdownProviderTests/ProviderTests.swift @@ -13,8 +13,8 @@ class ProviderTests: XCTestCase { func testProviderAddsTagToLeaf() throws { var services = Services.default() let leafProvider = LeafProvider() - services.use(leafProvider) - services.use(MarkdownProvider.Provider.self) + try services.register(leafProvider) + try services.register(MarkdownProvider.Provider()) let app = try Application(services: services) let renderer = try app.make(LeafRenderer.self, for: ViewRenderer.self) @@ -23,9 +23,9 @@ class ProviderTests: XCTestCase { } func testProviderGracefullyHandlesNonLeafRenderer() throws { - let app = try Application() - let leafProvider = MarkdownProvider.Provider() - try leafProvider.boot(app) + var services = Services.default() + try services.register(MarkdownProvider.Provider()) + _ = try Application(services: services) XCTAssert(true, "We should reach this point") } } From a2e14f2c1a69348dba0e72119ee62ebbd4e66566 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 12 Jan 2018 11:34:52 +0000 Subject: [PATCH 07/17] Update to latest TemplateKit changes --- Sources/MarkdownProvider/Provider.swift | 6 ++++-- Sources/MarkdownProvider/Tag.swift | 15 ++++++--------- Tests/MarkdownProviderTests/LeafTests.swift | 19 ++++++++++++------- .../MarkdownProviderTests/ProviderTests.swift | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index cf2e54e..5245649 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -6,12 +6,14 @@ public struct Provider: Vapor.Provider { public static let repositoryName = "markdown-provider" public func register(_ services: inout Services) throws { - print("Registered") + var tags = LeafTagConfig.default() + tags.use(Markdown(), as: "markdown") + services.register(tags) } public func boot(_ worker: Container) throws { do { - let renderer = try worker.make(LeafRenderer.self, for: ViewRenderer.self) + _ = try worker.make(LeafRenderer.self, for: TemplateRenderer.self) } catch is ServiceError { print("Markdown Provider only supports Leaf as a renderer - make sure the Leaf Provider has been registered") } diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/MarkdownProvider/Tag.swift index 9ec67c9..793c866 100644 --- a/Sources/MarkdownProvider/Tag.swift +++ b/Sources/MarkdownProvider/Tag.swift @@ -2,30 +2,27 @@ import Leaf import SwiftMarkdown import Async -public final class Markdown: LeafTag { +public final class Markdown: TagRenderer { public enum Error: Swift.Error { - case invalidArgument(LeafData?) + case invalidArgument(TemplateData?) } public let name = "markdown" - public func render(parsed: ParsedTag, context: LeafContext, renderer: LeafRenderer) throws -> Future { + public func render(tag: TagContext) throws -> Future { var markdown = "" - if let markdownArgument = parsed.parameters.first, !markdownArgument.isNull { + if let markdownArgument = tag.parameters.first, !markdownArgument.isNull { guard let markdownArgumentValue = markdownArgument.string else { - throw Error.invalidArgument(parsed.parameters.first) + throw Error.invalidArgument(tag.parameters.first) } markdown = markdownArgumentValue } let markdownHtml = try markdownToHTML(markdown) - - let promise = Promise(LeafData?.self) - promise.complete(.string(markdownHtml)) - return promise.future + return Future(.string(markdownHtml)) } } diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index 765befc..469822f 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -15,24 +15,29 @@ class LeafTests: XCTestCase { override func setUp() { let queue = DispatchEventLoop(label: "io.brokenhands.markdown-provider.test") + let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue) let tag = Markdown() - self.renderer = LeafRenderer(config: LeafConfig(tags: [tag.name: tag]), on: queue) + var leafTagConfig = LeafTagConfig.default() + leafTagConfig.use(tag, as: tag.name) + self.renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false), using: container) } func testRunTag() throws { let inputMarkdown = "# This is a test\n\nWe have some text in a tag" - let data = LeafData.dictionary(["data": .string(inputMarkdown)]) + let data = TemplateData.dictionary(["data": .string(inputMarkdown)]) let expectedHtml = "

This is a test

\n

We have some text in a tag

\n" - let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() - XCTAssertEqual(result, expectedHtml) + let result = try renderer.render(template: template.data(using: .utf8)!, data).blockingAwait() + let resultString = String(data: result.data, encoding: .utf8)! + XCTAssertEqual(resultString, expectedHtml) } func testNilParameterDoesNotCrashLeaf() throws { - let data = LeafData.dictionary(["data": .null]) + let data = TemplateData.dictionary(["data": .null]) let expectedHtml = "" - let result = try renderer.render(template, context: LeafContext(data: data)).blockingAwait() - XCTAssertEqual(result, expectedHtml) + let result = try renderer.render(template: template.data(using: .utf8)!, data).blockingAwait() + let resultString = String(data: result.data, encoding: .utf8)! + XCTAssertEqual(resultString, expectedHtml) } } diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/MarkdownProviderTests/ProviderTests.swift index e70b060..fe994d2 100644 --- a/Tests/MarkdownProviderTests/ProviderTests.swift +++ b/Tests/MarkdownProviderTests/ProviderTests.swift @@ -17,7 +17,7 @@ class ProviderTests: XCTestCase { try services.register(MarkdownProvider.Provider()) let app = try Application(services: services) - let renderer = try app.make(LeafRenderer.self, for: ViewRenderer.self) + let renderer = try app.make(LeafRenderer.self, for: TemplateRenderer.self) XCTAssertNotNil(renderer.tags[Markdown().name]) } From 3998fa20df9ec837866a60917220e23c18ea6398 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Thu, 22 Feb 2018 16:52:08 +0000 Subject: [PATCH 08/17] Update to tagged Leaf beta --- Package.swift | 4 ++-- Tests/MarkdownProviderTests/LeafTests.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 723d313..9d23583 100644 --- a/Package.swift +++ b/Package.swift @@ -8,8 +8,8 @@ let package = Package( .library(name: "MarkdownProvider", targets: ["MarkdownProvider"]), ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", .branch("beta")), - .package(url: "https://github.com/vapor/leaf.git", .branch("beta")), + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-beta"), + .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-beta"), .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), ], targets: [ diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index 469822f..bff0111 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -14,7 +14,7 @@ class LeafTests: XCTestCase { let template = "#markdown(data)" override func setUp() { - let queue = DispatchEventLoop(label: "io.brokenhands.markdown-provider.test") + let queue = try! DefaultEventLoop(label: "io.brokenhands.markdown-provider.test") let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue) let tag = Markdown() var leafTagConfig = LeafTagConfig.default() From 0e5746249a7c521e32e69a77876505039ff46fae Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 14:42:42 +0100 Subject: [PATCH 09/17] Make it compile with the RC --- Package.swift | 4 ++-- Sources/MarkdownProvider/Provider.swift | 6 +++++- Sources/MarkdownProvider/Tag.swift | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 9d23583..05a3df0 100644 --- a/Package.swift +++ b/Package.swift @@ -8,8 +8,8 @@ let package = Package( .library(name: "MarkdownProvider", targets: ["MarkdownProvider"]), ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-beta"), - .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-beta"), + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"), + .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc"), .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), ], targets: [ diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/MarkdownProvider/Provider.swift index 5245649..e393e2e 100644 --- a/Sources/MarkdownProvider/Provider.swift +++ b/Sources/MarkdownProvider/Provider.swift @@ -13,11 +13,15 @@ public struct Provider: Vapor.Provider { public func boot(_ worker: Container) throws { do { - _ = try worker.make(LeafRenderer.self, for: TemplateRenderer.self) + _ = try worker.make(LeafRenderer.self) } catch is ServiceError { print("Markdown Provider only supports Leaf as a renderer - make sure the Leaf Provider has been registered") } } + + public func didBoot(_ container: Container) throws -> EventLoopFuture { + return Future.map(on: container) {} + } // // public func boot(_ drop: Droplet) { // guard let renderer = drop.view as? LeafRenderer else { diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/MarkdownProvider/Tag.swift index 793c866..ba0fb84 100644 --- a/Sources/MarkdownProvider/Tag.swift +++ b/Sources/MarkdownProvider/Tag.swift @@ -21,8 +21,11 @@ public final class Markdown: TagRenderer { markdown = markdownArgumentValue } - let markdownHtml = try markdownToHTML(markdown) - return Future(.string(markdownHtml)) + let markdownHTML = try markdownToHTML(markdown) + + return Future.map(on: tag) { + .string(markdownHTML) + } } } From 11434c6edb217fcff02549c98c10910a43661784 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 14:48:48 +0100 Subject: [PATCH 10/17] Get the tests passing --- .travis.yml | 4 ++-- Tests/MarkdownProviderTests/LeafTests.swift | 6 +++--- Tests/MarkdownProviderTests/ProviderTests.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0aa57a..4c1765b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ language: generic sudo: required dist: trusty -osx_image: xcode9.2 +osx_image: xcode9.3 before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then - HOMEBREW_NO_AUTO_UPDATE=1 brew install vapor/tap/vapor; + brew install vapor/tap/vapor; else eval "$(curl -sL https://apt.vapor.sh)"; sudo apt-get install vapor; diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/MarkdownProviderTests/LeafTests.swift index bff0111..c23e91d 100644 --- a/Tests/MarkdownProviderTests/LeafTests.swift +++ b/Tests/MarkdownProviderTests/LeafTests.swift @@ -14,7 +14,7 @@ class LeafTests: XCTestCase { let template = "#markdown(data)" override func setUp() { - let queue = try! DefaultEventLoop(label: "io.brokenhands.markdown-provider.test") + let queue = EmbeddedEventLoop() let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue) let tag = Markdown() var leafTagConfig = LeafTagConfig.default() @@ -27,7 +27,7 @@ class LeafTests: XCTestCase { let data = TemplateData.dictionary(["data": .string(inputMarkdown)]) let expectedHtml = "

This is a test

\n

We have some text in a tag

\n" - let result = try renderer.render(template: template.data(using: .utf8)!, data).blockingAwait() + let result = try renderer.render(template: template.data(using: .utf8)!, data).wait() let resultString = String(data: result.data, encoding: .utf8)! XCTAssertEqual(resultString, expectedHtml) } @@ -36,7 +36,7 @@ class LeafTests: XCTestCase { let data = TemplateData.dictionary(["data": .null]) let expectedHtml = "" - let result = try renderer.render(template: template.data(using: .utf8)!, data).blockingAwait() + let result = try renderer.render(template: template.data(using: .utf8)!, data).wait() let resultString = String(data: result.data, encoding: .utf8)! XCTAssertEqual(resultString, expectedHtml) } diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/MarkdownProviderTests/ProviderTests.swift index fe994d2..245f957 100644 --- a/Tests/MarkdownProviderTests/ProviderTests.swift +++ b/Tests/MarkdownProviderTests/ProviderTests.swift @@ -17,7 +17,7 @@ class ProviderTests: XCTestCase { try services.register(MarkdownProvider.Provider()) let app = try Application(services: services) - let renderer = try app.make(LeafRenderer.self, for: TemplateRenderer.self) + let renderer = try app.make(LeafRenderer.self) XCTAssertNotNil(renderer.tags[Markdown().name]) } From 2d0961dc2059aac32603947252856b4afe4c3c23 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 14:57:20 +0100 Subject: [PATCH 11/17] Rename project --- Package.swift | 8 ++++---- Sources/{MarkdownProvider => LeafMarkdown}/Provider.swift | 0 Sources/{MarkdownProvider => LeafMarkdown}/Tag.swift | 0 .../LeafTests.swift | 0 .../ProviderTests.swift | 0 Tests/LinuxMain.swift | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename Sources/{MarkdownProvider => LeafMarkdown}/Provider.swift (100%) rename Sources/{MarkdownProvider => LeafMarkdown}/Tag.swift (100%) rename Tests/{MarkdownProviderTests => LeafMarkdownTests}/LeafTests.swift (100%) rename Tests/{MarkdownProviderTests => LeafMarkdownTests}/ProviderTests.swift (100%) diff --git a/Package.swift b/Package.swift index 05a3df0..81b4680 100644 --- a/Package.swift +++ b/Package.swift @@ -3,9 +3,9 @@ import PackageDescription let package = Package( - name: "MarkdownProvider", + name: "LeafMarkdown", products: [ - .library(name: "MarkdownProvider", targets: ["MarkdownProvider"]), + .library(name: "LeafMarkdown", targets: ["LeafMarkdown"]), ], dependencies: [ .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"), @@ -13,7 +13,7 @@ let package = Package( .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), ], targets: [ - .target(name: "MarkdownProvider", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), - .testTarget(name: "MarkdownProviderTests", dependencies: ["MarkdownProvider"]), + .target(name: "LeafMarkdown", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), + .testTarget(name: "LeafMarkdownTests", dependencies: ["LeafMarkdown"]), ] ) diff --git a/Sources/MarkdownProvider/Provider.swift b/Sources/LeafMarkdown/Provider.swift similarity index 100% rename from Sources/MarkdownProvider/Provider.swift rename to Sources/LeafMarkdown/Provider.swift diff --git a/Sources/MarkdownProvider/Tag.swift b/Sources/LeafMarkdown/Tag.swift similarity index 100% rename from Sources/MarkdownProvider/Tag.swift rename to Sources/LeafMarkdown/Tag.swift diff --git a/Tests/MarkdownProviderTests/LeafTests.swift b/Tests/LeafMarkdownTests/LeafTests.swift similarity index 100% rename from Tests/MarkdownProviderTests/LeafTests.swift rename to Tests/LeafMarkdownTests/LeafTests.swift diff --git a/Tests/MarkdownProviderTests/ProviderTests.swift b/Tests/LeafMarkdownTests/ProviderTests.swift similarity index 100% rename from Tests/MarkdownProviderTests/ProviderTests.swift rename to Tests/LeafMarkdownTests/ProviderTests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index c456759..3d445ed 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,6 +1,6 @@ import XCTest -@testable import MarkdownProviderTests +@testable import LeafMakrdownTests XCTMain([ testCase(LeafTests.allTests), From 705f87a0f3c3a18fbac6df5b63edecac758323fa Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 15:06:07 +0100 Subject: [PATCH 12/17] Fix tests from rename --- README.md | 25 ++++++--------------- Sources/LeafMarkdown/Provider.swift | 2 ++ Sources/LeafMarkdown/Tag.swift | 2 ++ Tests/LeafMarkdownTests/LeafTests.swift | 2 +- Tests/LeafMarkdownTests/ProviderTests.swift | 6 ++--- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index cb6916e..92a31bc 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Markdown Provider +# Leaf Markdown [![Language](https://img.shields.io/badge/Swift-4-brightgreen.svg)](http://swift.org) -[![Build Status](https://travis-ci.org/vapor-community/markdown-provider.svg?branch=master)](https://travis-ci.org/vapor-community/markdown-provider) -[![codecov](https://codecov.io/gh/vapor-community/markdown-provider/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor-community/mmarkdown-provider) -[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vapor-community/markdown-provider/master/LICENSE) +[![Build Status](https://travis-ci.org/vapor-community/leaf-markdown.svg?branch=master)](https://travis-ci.org/vapor-community/leaf-markdown) +[![codecov](https://codecov.io/gh/vapor-community/leaf-markdown/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor-community/leaf-markdown) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vapor-community/leaf-markdown/master/LICENSE) -A Markdown renderer for Vapor and Leaf. This uses the [Vapor Markdown](https://github.com/vapor/markdown) package to wrap [cmark](https://github.com/jgm/cmark) (though a [fork](https://github.com/brokenhandsio/cmark-gfm) is used to make it work with Swift PM), so it understands [Common Mark](http://commonmark.org). A quick reference guide for Common Mark can be found [here](http://commonmark.org/help/). It also support [Github Flavored Markdown](https://guides.github.com/features/mastering-markdown/) +A Markdown renderer for Vapor and Leaf. This uses the [Vapor Markdown](https://github.com/vapor/markdown) package to wrap [cmark](https://github.com/jgm/cmark) (though a [fork](https://github.com/brokenhandsio/cmark-gfm) is used to make it work with Swift PM), so it understands [Common Mark](http://commonmark.org). A quick reference guide for Common Mark can be found [here](http://commonmark.org/help/). It also supports [Github Flavored Markdown](https://guides.github.com/features/mastering-markdown/). ## Use @@ -27,26 +27,15 @@ Check out my *awesome* markdown! It is easy to use in `tags` ### Add as dependency -Add Markdown Provider as a dependency in your `Package.swift` file: +Add Leaf Markdown as a dependency in your `Package.swift` file: ```swift dependencies: [ ..., - .package(url: "https://github.com/vapor-community/markdown-provider.git", .upToNextMajor(from: "1.1.0")) + .package(url: "https://github.com/vapor-community/leaf-markdown.git", .upToNextMajor(from: "2.0.0")) ] ``` -### Add the Provider - -You can add a provider to you `Config`, which will do all of the setup for you and register your tag. Just add it as so: - -```swift -let config = try Config() -try config.addProvider(MarkdownProvider.Provider.self) -let drop = try Droplet(config) -``` - - ### Register with Leaf Alternatively, you can also directly add the Tag onto your `LeafRenderer` if desired. During your setup (for example, in `Droplet+Setup.swift`), register your tag as so: diff --git a/Sources/LeafMarkdown/Provider.swift b/Sources/LeafMarkdown/Provider.swift index e393e2e..6e952b5 100644 --- a/Sources/LeafMarkdown/Provider.swift +++ b/Sources/LeafMarkdown/Provider.swift @@ -5,6 +5,8 @@ public struct Provider: Vapor.Provider { public static let repositoryName = "markdown-provider" + public init() {} + public func register(_ services: inout Services) throws { var tags = LeafTagConfig.default() tags.use(Markdown(), as: "markdown") diff --git a/Sources/LeafMarkdown/Tag.swift b/Sources/LeafMarkdown/Tag.swift index ba0fb84..b5c3004 100644 --- a/Sources/LeafMarkdown/Tag.swift +++ b/Sources/LeafMarkdown/Tag.swift @@ -10,6 +10,8 @@ public final class Markdown: TagRenderer { public let name = "markdown" + public init() {} + public func render(tag: TagContext) throws -> Future { var markdown = "" diff --git a/Tests/LeafMarkdownTests/LeafTests.swift b/Tests/LeafMarkdownTests/LeafTests.swift index c23e91d..122b722 100644 --- a/Tests/LeafMarkdownTests/LeafTests.swift +++ b/Tests/LeafMarkdownTests/LeafTests.swift @@ -2,7 +2,7 @@ import XCTest import Vapor @testable import Leaf -@testable import MarkdownProvider +import LeafMarkdown class LeafTests: XCTestCase { static var allTests = [ diff --git a/Tests/LeafMarkdownTests/ProviderTests.swift b/Tests/LeafMarkdownTests/ProviderTests.swift index 245f957..1ed9a83 100644 --- a/Tests/LeafMarkdownTests/ProviderTests.swift +++ b/Tests/LeafMarkdownTests/ProviderTests.swift @@ -2,7 +2,7 @@ import XCTest import Vapor import Leaf -@testable import MarkdownProvider +import LeafMarkdown class ProviderTests: XCTestCase { static var allTests = [ @@ -14,7 +14,7 @@ class ProviderTests: XCTestCase { var services = Services.default() let leafProvider = LeafProvider() try services.register(leafProvider) - try services.register(MarkdownProvider.Provider()) + try services.register(LeafMarkdown.Provider()) let app = try Application(services: services) let renderer = try app.make(LeafRenderer.self) @@ -24,7 +24,7 @@ class ProviderTests: XCTestCase { func testProviderGracefullyHandlesNonLeafRenderer() throws { var services = Services.default() - try services.register(MarkdownProvider.Provider()) + try services.register(LeafMarkdown.Provider()) _ = try Application(services: services) XCTAssert(true, "We should reach this point") } From ee51b75cee944c7f73d87d016cb320f4bcea1e61 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 15:45:31 +0100 Subject: [PATCH 13/17] Remove provider and update README --- README.md | 15 +++++---- Sources/LeafMarkdown/Provider.swift | 36 --------------------- Tests/LeafMarkdownTests/ProviderTests.swift | 31 ------------------ Tests/LeafMarkdownTests/ServicesTests.swift | 23 +++++++++++++ Tests/LinuxMain.swift | 2 +- 5 files changed, 33 insertions(+), 74 deletions(-) delete mode 100644 Sources/LeafMarkdown/Provider.swift delete mode 100644 Tests/LeafMarkdownTests/ProviderTests.swift create mode 100644 Tests/LeafMarkdownTests/ServicesTests.swift diff --git a/README.md b/README.md index 92a31bc..8c6b8d3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A Markdown renderer for Vapor and Leaf. This uses the [Vapor Markdown](https://github.com/vapor/markdown) package to wrap [cmark](https://github.com/jgm/cmark) (though a [fork](https://github.com/brokenhandsio/cmark-gfm) is used to make it work with Swift PM), so it understands [Common Mark](http://commonmark.org). A quick reference guide for Common Mark can be found [here](http://commonmark.org/help/). It also supports [Github Flavored Markdown](https://guides.github.com/features/mastering-markdown/). -## Use +## Usage Once set up, you can use it in your Leaf template files like any other tag: @@ -38,12 +38,15 @@ Add Leaf Markdown as a dependency in your `Package.swift` file: ### Register with Leaf -Alternatively, you can also directly add the Tag onto your `LeafRenderer` if desired. During your setup (for example, in `Droplet+Setup.swift`), register your tag as so: +To add the tag to Leaf, add it to your `LeafTagConfig`: ```swift -if let leaf = drop.view as? LeafRenderer { - leaf.stem.register(Markdown()) -} +try services.register(LeafProvider()) +var tags = LeafTagConfig.default() +tags.use(Markdown(), as: "markdown") +services.register(tags) ``` -Don't forget to import MarkdownProvider in the file you register the tag or add the provider in with `import MarkdownProvider` +**Note:** it's important that you register the `LeafProvider` first otherwise this will override your `LeafTagConfig`. + +Don't forget to import LeafMarkdown in the file you register the tag with `import LeafMarkdown`. diff --git a/Sources/LeafMarkdown/Provider.swift b/Sources/LeafMarkdown/Provider.swift deleted file mode 100644 index 6e952b5..0000000 --- a/Sources/LeafMarkdown/Provider.swift +++ /dev/null @@ -1,36 +0,0 @@ -import Vapor -import Leaf - -public struct Provider: Vapor.Provider { - - public static let repositoryName = "markdown-provider" - - public init() {} - - public func register(_ services: inout Services) throws { - var tags = LeafTagConfig.default() - tags.use(Markdown(), as: "markdown") - services.register(tags) - } - - public func boot(_ worker: Container) throws { - do { - _ = try worker.make(LeafRenderer.self) - } catch is ServiceError { - print("Markdown Provider only supports Leaf as a renderer - make sure the Leaf Provider has been registered") - } - } - - public func didBoot(_ container: Container) throws -> EventLoopFuture { - return Future.map(on: container) {} - } -// -// public func boot(_ drop: Droplet) { -// guard let renderer = drop.view as? LeafRenderer else { -// print("Markdown Provider only supports Leaf as a renderer") -// return -// } -// -// renderer.stem.register(Markdown()) -// } -} diff --git a/Tests/LeafMarkdownTests/ProviderTests.swift b/Tests/LeafMarkdownTests/ProviderTests.swift deleted file mode 100644 index 1ed9a83..0000000 --- a/Tests/LeafMarkdownTests/ProviderTests.swift +++ /dev/null @@ -1,31 +0,0 @@ -import XCTest -import Vapor -import Leaf - -import LeafMarkdown - -class ProviderTests: XCTestCase { - static var allTests = [ - ("testProviderCreation", testProviderAddsTagToLeaf), - ("testProviderGracefullyHandlesNonLeafRenderer", testProviderGracefullyHandlesNonLeafRenderer) - ] - - func testProviderAddsTagToLeaf() throws { - var services = Services.default() - let leafProvider = LeafProvider() - try services.register(leafProvider) - try services.register(LeafMarkdown.Provider()) - let app = try Application(services: services) - - let renderer = try app.make(LeafRenderer.self) - - XCTAssertNotNil(renderer.tags[Markdown().name]) - } - - func testProviderGracefullyHandlesNonLeafRenderer() throws { - var services = Services.default() - try services.register(LeafMarkdown.Provider()) - _ = try Application(services: services) - XCTAssert(true, "We should reach this point") - } -} diff --git a/Tests/LeafMarkdownTests/ServicesTests.swift b/Tests/LeafMarkdownTests/ServicesTests.swift new file mode 100644 index 0000000..58f4ca5 --- /dev/null +++ b/Tests/LeafMarkdownTests/ServicesTests.swift @@ -0,0 +1,23 @@ +import XCTest +import Vapor +import Leaf + +import LeafMarkdown + +class ServicesTests: XCTestCase { + static var allTests = [ + ("testTagsCanBeAddedToServices", testTagsCanBeAddedToServices), + ] + + func testTagsCanBeAddedToServices() throws { + var services = Services.default() + try services.register(LeafProvider()) + var tags = LeafTagConfig.default() + tags.use(Markdown(), as: "markdown") + services.register(tags) + let app = try Application(services: services) + let renderer = try app.make(LeafRenderer.self) + + XCTAssertNotNil(renderer.tags[Markdown().name]) + } +} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 3d445ed..c3fbd0f 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -4,5 +4,5 @@ import XCTest XCTMain([ testCase(LeafTests.allTests), - testCase(ProviderTests.allTests) + testCase(ServicesTests.allTests) ]) From 113ce719368ac33e5c18393c55ec58e362e2ff0e Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 16:31:12 +0100 Subject: [PATCH 14/17] Swiftlint --- Tests/LeafMarkdownTests/LeafTests.swift | 3 ++- Tests/LeafMarkdownTests/ServicesTests.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/LeafMarkdownTests/LeafTests.swift b/Tests/LeafMarkdownTests/LeafTests.swift index 122b722..c41daae 100644 --- a/Tests/LeafMarkdownTests/LeafTests.swift +++ b/Tests/LeafMarkdownTests/LeafTests.swift @@ -19,7 +19,8 @@ class LeafTests: XCTestCase { let tag = Markdown() var leafTagConfig = LeafTagConfig.default() leafTagConfig.use(tag, as: tag.name) - self.renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false), using: container) + self.renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false), + using: container) } func testRunTag() throws { diff --git a/Tests/LeafMarkdownTests/ServicesTests.swift b/Tests/LeafMarkdownTests/ServicesTests.swift index 58f4ca5..a5b40f7 100644 --- a/Tests/LeafMarkdownTests/ServicesTests.swift +++ b/Tests/LeafMarkdownTests/ServicesTests.swift @@ -6,7 +6,7 @@ import LeafMarkdown class ServicesTests: XCTestCase { static var allTests = [ - ("testTagsCanBeAddedToServices", testTagsCanBeAddedToServices), + ("testTagsCanBeAddedToServices", testTagsCanBeAddedToServices) ] func testTagsCanBeAddedToServices() throws { From 12da8e962b5f579037c05db1753864020cdeb4d1 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 4 May 2018 16:34:47 +0100 Subject: [PATCH 15/17] Fix tests on Linux --- Tests/LinuxMain.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index c3fbd0f..6f98444 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,6 +1,6 @@ import XCTest -@testable import LeafMakrdownTests +@testable import LeafMarkdownTests XCTMain([ testCase(LeafTests.allTests), From 6440f2ef329065ba9a6af8d3fbd3e6cde086b56d Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 10 Aug 2018 19:31:39 +0100 Subject: [PATCH 16/17] Use Leaf release --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 81b4680..0553068 100644 --- a/Package.swift +++ b/Package.swift @@ -8,8 +8,8 @@ let package = Package( .library(name: "LeafMarkdown", targets: ["LeafMarkdown"]), ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"), - .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc"), + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), + .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"), .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), ], targets: [ From 8cd9f4e22801e26211b548e2f60f8c26db1ee021 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Fri, 10 Aug 2018 19:47:45 +0100 Subject: [PATCH 17/17] update to Xcode 9.4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4c1765b..99e1887 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: generic sudo: required dist: trusty -osx_image: xcode9.3 +osx_image: xcode9.4 before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then brew install vapor/tap/vapor;