From a898d75b1a8c011fa4156ddb035813495bea1b43 Mon Sep 17 00:00:00 2001 From: "Steffen D. Sommer" Date: Mon, 11 Jun 2018 10:59:17 +0200 Subject: [PATCH 1/3] Finalize readme --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 193281e..8e14a8a 100644 --- a/README.md +++ b/README.md @@ -36,21 +36,83 @@ public func register(_ services: inout Services) throws { ### Adding the middleware -TODO +You can either add the Flash middleware globally by doing: + +```swift +public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws { + var middlewares = MiddlewareConfig() + middlewares.use(FlashMiddleware.self) + middlewares.use(SessionsMiddleware.self) + services.register(middlewares) +} +``` + +Alternatively, you can add the middleware to individual route groups where needed: + +```swift +router.group(FlashMiddleware()) { router in + // .. routes +} +``` + +Please note that the `SessionsMiddleware` needs to be added to the same route groups where Flash is added. ### Adding the Leaf tag -TODO +In order to render Flash messages, you will need to add the Flash leaf tag: + +```swift +public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws { + services.register { _ -> LeafTagConfig in + var tags = LeafTagConfig.default() + tags.use(FlashTag(), as: "flash") + return tags + } +} +``` ## Using Flash messages -TODO +With Flash set up, you are now able to redirect while adding a Flash message, given a `Request`: + +```swift +request.redirect(to: "/users").flash(.success, "Successfully saved") +request.redirect(to: "/users").flash(.info, "Email sent") +request.redirect(to: "/users").flash(.warning, "Updated user") +request.redirect(to: "/users").flash(.error, "Something went wrong") +``` ### Example of HTML +This package comes with a Leaf tag that makes it easy and convenient to display Flash messages. We suggest to use the [Bootstrap package](https://github.com/nodes-vapor/bootstrap) for rendering Bootstrap elements, but this package does not depend on it. + +It's possible to loop through the different kinds of messages using: + +- `all`: All Flash messages no matter the kind. +- `successes`: All Flash messages of type `success`. +- `information`: All Flash messages of type `info`. +- `warnings`: All Flash messages of type `warning`. +- `errors`: All Flash messages of type `error`. + +Further, using the `message` property you will be able to pull out the message of the Flash message. You can also get the kind by using the `kind` property. This property will hold one of the following values: `success`, `info`, `warning` or `error`. Lastly, you can use the `bootstrapClass` to get the relevant Bootstrap class: + +- `success` will return `success`. +- `info` will return `info`. +- `warning` will return `warning`. +- `error` will return `danger`. + #### Not using the Bootstrap package -TODO +Without using any dependencies, this is how Flash messages could be rendered: + +
+#flash() { + #for(flash in all) { + Message: #(flash.message) + Type: #(flash.kind) + } +} +
#### Using the Bootstrap package @@ -60,7 +122,7 @@ The below example uses the Vapor 3 [Bootstrap package](https://github.com/nodes-
#flash() { #for(flash in all) { - #bs:alert(flash.bootstrapType) { + #bs:alert(flash.bootstrapClass) { #(flash.message) } } From 3d4459ac95231e761c2268c3e73be53dbdf54a10 Mon Sep 17 00:00:00 2001 From: "Steffen D. Sommer" Date: Mon, 11 Jun 2018 11:04:02 +0200 Subject: [PATCH 2/3] Typo fixes --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e14a8a..46779c6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/flash)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/flash) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/flash/master/LICENSE) -This package is to ease using flash message between your views +This package allows you to display Flash messages between your views. ![image](https://github.com/nodes-vapor/flash/blob/master/flash.png) @@ -105,6 +105,7 @@ Further, using the `message` property you will be able to pull out the message o Without using any dependencies, this is how Flash messages could be rendered: +```html
#flash() { #for(flash in all) { @@ -113,6 +114,7 @@ Without using any dependencies, this is how Flash messages could be rendered: } }
+``` #### Using the Bootstrap package From 762792f960a857db8a1c216edc6329f71a3cc5c5 Mon Sep 17 00:00:00 2001 From: "Steffen D. Sommer" Date: Mon, 11 Jun 2018 11:12:13 +0200 Subject: [PATCH 3/3] Remove dependency lock file --- Package.resolved | 169 ----------------------------------------------- 1 file changed, 169 deletions(-) delete mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index be251b0..0000000 --- a/Package.resolved +++ /dev/null @@ -1,169 +0,0 @@ -{ - "object": { - "pins": [ - { - "package": "Console", - "repositoryURL": "https://github.com/vapor/console.git", - "state": { - "branch": null, - "revision": "5b9796d39f201b3dd06800437abd9d774a455e57", - "version": "3.0.2" - } - }, - { - "package": "Core", - "repositoryURL": "https://github.com/vapor/core.git", - "state": { - "branch": null, - "revision": "efe79e4f59445b661ba7e6511c2a0b80645c2e72", - "version": "3.1.6" - } - }, - { - "package": "Crypto", - "repositoryURL": "https://github.com/vapor/crypto.git", - "state": { - "branch": null, - "revision": "346ae2b2ea65a4b6f4985a8e8cb25cf61da549d8", - "version": "3.1.1" - } - }, - { - "package": "DatabaseKit", - "repositoryURL": "https://github.com/vapor/database-kit.git", - "state": { - "branch": null, - "revision": "0db303439e5ef8b6df50a2b6c4029edddee90cb0", - "version": "1.0.1" - } - }, - { - "package": "HTTP", - "repositoryURL": "https://github.com/vapor/http.git", - "state": { - "branch": null, - "revision": "82b97f68471830759a3a8f90f53df243d0c97db1", - "version": "3.0.4" - } - }, - { - "package": "Leaf", - "repositoryURL": "https://github.com/vapor/leaf.git", - "state": { - "branch": null, - "revision": "8cc35dcfcd8f9ed142a954f70431a05e866ca040", - "version": "3.0.0-rc.2.1.2" - } - }, - { - "package": "Multipart", - "repositoryURL": "https://github.com/vapor/multipart.git", - "state": { - "branch": null, - "revision": "7778dcb62f3efa845e8e2808937bb347575ba7ce", - "version": "3.0.1" - } - }, - { - "package": "Routing", - "repositoryURL": "https://github.com/vapor/routing.git", - "state": { - "branch": null, - "revision": "3219e328491b0853b8554c5a694add344d2c6cfb", - "version": "3.0.1" - } - }, - { - "package": "Service", - "repositoryURL": "https://github.com/vapor/service.git", - "state": { - "branch": null, - "revision": "281a70b69783891900be31a9e70051b6fe19e146", - "version": "1.0.0" - } - }, - { - "package": "swift-nio", - "repositoryURL": "https://github.com/apple/swift-nio.git", - "state": { - "branch": null, - "revision": "8bf1be06728214f9698b4ee13bdb6ebffe35a40b", - "version": "1.6.0" - } - }, - { - "package": "swift-nio-ssl", - "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", - "state": { - "branch": null, - "revision": "38955a5f806a952daf2b16fbfe9aa529749cf1dd", - "version": "1.1.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": "43b57b5861d5181b906ac6411d28645e980bb638", - "version": "1.0.1" - } - }, - { - "package": "URLEncodedForm", - "repositoryURL": "https://github.com/vapor/url-encoded-form.git", - "state": { - "branch": null, - "revision": "8448fa943057c01220f6a940d3b1b8e9fd92a96e", - "version": "1.0.2" - } - }, - { - "package": "Validation", - "repositoryURL": "https://github.com/vapor/validation.git", - "state": { - "branch": null, - "revision": "ab6c5a352d97c8687b91ed4963aef8e7cfe0795b", - "version": "2.0.0" - } - }, - { - "package": "Vapor", - "repositoryURL": "https://github.com/vapor/vapor.git", - "state": { - "branch": null, - "revision": "c834f9495ff5ab9768b74f5822ff23d795e36922", - "version": "3.0.0-rc.2.8.1" - } - }, - { - "package": "WebSocket", - "repositoryURL": "https://github.com/vapor/websocket.git", - "state": { - "branch": null, - "revision": "23acd21aa37a200faa2f5d5525c974efa6b5676c", - "version": "1.0.0" - } - } - ] - }, - "version": 1 -}