-
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 #3 from brokenhandsio/master
Merge Broken Hands work
- Loading branch information
Showing
18 changed files
with
242 additions
and
145 deletions.
There are no files selected for viewing
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,4 @@ | ||
coverage: | ||
range: "0...100" | ||
ignore: | ||
- "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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/.build | ||
/Packages | ||
/*.xcodeproj | ||
Package.pins | ||
DerivedData/ |
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 +1 @@ | ||
DEVELOPMENT-SNAPSHOT-2016-08-18-a | ||
3.1 |
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,26 @@ | ||
os: | ||
- linux | ||
- osx | ||
language: generic | ||
sudo: required | ||
dist: trusty | ||
|
||
osx_image: xcode8.3 | ||
before_install: | ||
- if [ $TRAVIS_OS_NAME == "osx" ]; then | ||
brew tap vapor/tap; | ||
brew update; | ||
brew install vapor; | ||
else | ||
eval "$(curl -sL https://apt.vapor.sh)"; | ||
sudo apt-get install vapor; | ||
sudo chmod -R a+rx /usr/; | ||
fi | ||
|
||
script: | ||
- swift build | ||
- swift build -c release | ||
- swift test | ||
|
||
after_success: | ||
- eval "$(curl -sL https://swift.vapor.sh/codecov)" |
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,12 +1,10 @@ | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "vapor-markdown", | ||
targets: [ | ||
Target(name: "vapor-markdown-example", dependencies: ["vapor-markdown"]) | ||
], | ||
name: "MarkdownProvider", | ||
dependencies: [ | ||
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 0, minor: 17), | ||
.Package(url: "https://github.com/czechboy0/cmark.swift.git", majorVersion: 0, minor: 1) | ||
.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) | ||
] | ||
) |
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,5 +1,59 @@ | ||
# vapor-markdown | ||
# Markdown Provider | ||
|
||
> Markdown renderer for Vapor | ||
[![Language](https://img.shields.io/badge/Swift-3.1-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) | ||
|
||
WIP | ||
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/) | ||
|
||
## Use | ||
|
||
Once set up, you can use it in your Leaf template files like any other tag: | ||
|
||
```swift | ||
#markdown(myMarkdown) | ||
``` | ||
|
||
Where you have passed `myMarkdown` into the view as something like: | ||
|
||
```markdown | ||
# Hey # | ||
|
||
Check out my *awesome* markdown! It is easy to use in `tags` | ||
``` | ||
|
||
## Setup | ||
|
||
### Add as dependency | ||
|
||
Add Markdown Provider as a dependency in your `Package.swift` file: | ||
|
||
```swift | ||
dependencies: [ | ||
..., | ||
.Package(url: "https://github.com/vapor-community/markdown-provider", majorVersion: 0) | ||
] | ||
``` | ||
|
||
### Add the Provider | ||
|
||
You can add a provider to you `Droplet`, which will do all of the setup for you and register your tag. Just add it as so: | ||
|
||
```swift | ||
let drop = Droplet() | ||
try drop.addProvider(MarkdownProvider.Provider.self) | ||
``` | ||
|
||
|
||
### Register with Leaf | ||
|
||
Alternatively, you can also directly add the Tag onto your `LeafRenderer` if desired. During your setup (for example, in `main.swift`), register your tag as so: | ||
|
||
```swift | ||
if let leaf = drop.view as? LeafRenderer { | ||
leaf.stem.register(Markdown()) | ||
} | ||
``` | ||
|
||
Don't forget to import MarkdownProvider in the file you register the tag or add the provider in with `import MarkdownProvider` |
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,21 @@ | ||
import Vapor | ||
import LeafProvider | ||
|
||
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("LeafMarkdown 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) {} | ||
} |
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 | ||
|
||
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) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
import XCTest | ||
|
||
@testable import MarkdownProviderTests | ||
|
||
XCTMain([ | ||
testCase(LeafTests.allTests), | ||
testCase(ProviderTests.allTests) | ||
]) |
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,51 @@ | ||
import XCTest | ||
import Vapor | ||
|
||
@testable import Leaf | ||
@testable import MarkdownProvider | ||
|
||
class LeafTests: XCTestCase { | ||
static var allTests = [ | ||
("testRunTag", testRunTag), | ||
("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf), | ||
] | ||
|
||
func testRunTag() { | ||
let tag = Markdown() | ||
let inputMarkdown = "# This is a test\n\nWe have some text in a tag" | ||
let expectedHtml = "<h1>This is a test</h1>\n<p>We have some text in a tag</p>\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) | ||
} | ||
catch { | ||
XCTFail() | ||
} | ||
} | ||
|
||
func testNilParameterDoesNotCrashLeaf() { | ||
let tag = Markdown() | ||
let expectedHtml = "" | ||
|
||
do { | ||
let node = try run(tag: tag, context: nil, arguments: []) | ||
XCTAssertEqual(node?.string, expectedHtml) | ||
} | ||
catch { | ||
XCTFail("Markdown Tag threw exception") | ||
} | ||
} | ||
} | ||
|
||
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 | ||
) | ||
} | ||
} |
Oops, something went wrong.