Skip to content

Commit

Permalink
Remove provider and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed May 4, 2018
1 parent 705f87a commit ee51b75
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 74 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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`.
36 changes: 0 additions & 36 deletions Sources/LeafMarkdown/Provider.swift

This file was deleted.

31 changes: 0 additions & 31 deletions Tests/LeafMarkdownTests/ProviderTests.swift

This file was deleted.

23 changes: 23 additions & 0 deletions Tests/LeafMarkdownTests/ServicesTests.swift
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])
}
}
2 changes: 1 addition & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import XCTest

XCTMain([
testCase(LeafTests.allTests),
testCase(ProviderTests.allTests)
testCase(ServicesTests.allTests)
])

0 comments on commit ee51b75

Please sign in to comment.