-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from vapor-community/vapor3
Vapor 3
- Loading branch information
Showing
14 changed files
with
136 additions
and
199 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
included: | ||
- Sources | ||
- Tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
// swift-tools-version:4.0 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MarkdownProvider", | ||
name: "LeafMarkdown", | ||
products: [ | ||
.library(name: "LeafMarkdown", targets: ["LeafMarkdown"]), | ||
], | ||
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", 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: [ | ||
.target(name: "LeafMarkdown", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), | ||
.testTarget(name: "LeafMarkdownTests", dependencies: ["LeafMarkdown"]), | ||
] | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Leaf | ||
import SwiftMarkdown | ||
import Async | ||
|
||
public final class Markdown: TagRenderer { | ||
|
||
public enum Error: Swift.Error { | ||
case invalidArgument(TemplateData?) | ||
} | ||
|
||
public let name = "markdown" | ||
|
||
public init() {} | ||
|
||
public func render(tag: TagContext) throws -> Future<TemplateData> { | ||
|
||
var markdown = "" | ||
|
||
if let markdownArgument = tag.parameters.first, !markdownArgument.isNull { | ||
guard let markdownArgumentValue = markdownArgument.string else { | ||
throw Error.invalidArgument(tag.parameters.first) | ||
} | ||
markdown = markdownArgumentValue | ||
} | ||
|
||
let markdownHTML = try markdownToHTML(markdown) | ||
|
||
return Future.map(on: tag) { | ||
.string(markdownHTML) | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import XCTest | ||
import Vapor | ||
|
||
@testable import Leaf | ||
import LeafMarkdown | ||
|
||
class LeafTests: XCTestCase { | ||
static var allTests = [ | ||
("testRunTag", testRunTag), | ||
("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf) | ||
] | ||
|
||
var renderer: LeafRenderer! | ||
let template = "#markdown(data)" | ||
|
||
override func setUp() { | ||
let queue = EmbeddedEventLoop() | ||
let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue) | ||
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) | ||
} | ||
|
||
func testRunTag() throws { | ||
let inputMarkdown = "# This is a test\n\nWe have some text in a tag" | ||
let data = TemplateData.dictionary(["data": .string(inputMarkdown)]) | ||
let expectedHtml = "<h1>This is a test</h1>\n<p>We have some text in a tag</p>\n" | ||
|
||
let result = try renderer.render(template: template.data(using: .utf8)!, data).wait() | ||
let resultString = String(data: result.data, encoding: .utf8)! | ||
XCTAssertEqual(resultString, expectedHtml) | ||
} | ||
|
||
func testNilParameterDoesNotCrashLeaf() throws { | ||
let data = TemplateData.dictionary(["data": .null]) | ||
let expectedHtml = "" | ||
|
||
let result = try renderer.render(template: template.data(using: .utf8)!, data).wait() | ||
let resultString = String(data: result.data, encoding: .utf8)! | ||
XCTAssertEqual(resultString, expectedHtml) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import XCTest | ||
|
||
@testable import MarkdownProviderTests | ||
@testable import LeafMarkdownTests | ||
|
||
XCTMain([ | ||
testCase(LeafTests.allTests), | ||
testCase(ProviderTests.allTests) | ||
testCase(ServicesTests.allTests) | ||
]) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.