All Projects → nodes-vapor → flash

nodes-vapor / flash

Licence: MIT license
Flash messages between views ⚡️

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to flash

paginator
Offset pagination for Vapor 🗂
Stars: ✭ 67 (+97.06%)
Mutual labels:  vapor, server-side-swift, vapor-2
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (+8.82%)
Mutual labels:  vapor, server-side-swift, vapor-2
sourcery-templates
Building Vapor projects using meta programming with Sourcery ✨
Stars: ✭ 24 (-29.41%)
Mutual labels:  vapor, server-side-swift, vapor-2
gatekeeper
Rate limiting middleware for Vapor 👮
Stars: ✭ 54 (+58.82%)
Mutual labels:  vapor, server-side-swift, vapor-3
template
A Vapor template for convenient and fast scaffolding 🏎
Stars: ✭ 33 (-2.94%)
Mutual labels:  vapor, server-side-swift, vapor-2
VaporTwilioService
Twilio API provider for all your Vapor needs
Stars: ✭ 19 (-44.12%)
Mutual labels:  vapor, server-side-swift
sqlite-kit
Non-blocking SQLite client library with SQL builder built on SwiftNIO
Stars: ✭ 51 (+50%)
Mutual labels:  vapor, server-side-swift
routing-kit
🚍 High-performance trie-node router.
Stars: ✭ 95 (+179.41%)
Mutual labels:  vapor, server-side-swift
fluent-mysql-driver
🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
Stars: ✭ 69 (+102.94%)
Mutual labels:  vapor, server-side-swift
fluent-postgres-driver
🐘 PostgreSQL driver for Fluent.
Stars: ✭ 120 (+252.94%)
Mutual labels:  vapor, server-side-swift
async
⏱ Promises and reactive-streams in Swift built for high-performance and scalability.
Stars: ✭ 35 (+2.94%)
Mutual labels:  vapor, server-side-swift
apns
Vapor APNS for iOS
Stars: ✭ 59 (+73.53%)
Mutual labels:  vapor, vapor-3
readme
Welcome to Vapor development at Nodes 📖
Stars: ✭ 47 (+38.24%)
Mutual labels:  vapor, server-side-swift
VaporElasticsearch
A Vapor/Swift Elasticsearch client
Stars: ✭ 26 (-23.53%)
Mutual labels:  vapor, vapor-3
Console Kit
💻 APIs for creating interactive CLI tools.
Stars: ✭ 252 (+641.18%)
Mutual labels:  vapor, server-side-swift
Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+629.41%)
Mutual labels:  vapor, server-side-swift
GraphQLRouteCollection
A GraphQL based RouteCollection for Vapor
Stars: ✭ 18 (-47.06%)
Mutual labels:  vapor, server-side-swift
HomeKitty
A Vapor 3 website to easily browse HomeKit accessories.
Stars: ✭ 75 (+120.59%)
Mutual labels:  vapor, server-side-swift
auth
👤 Authentication and Authorization framework for Fluent.
Stars: ✭ 51 (+50%)
Mutual labels:  vapor, server-side-swift
Http
🚀 Non-blocking, event-driven HTTP built on Swift NIO.
Stars: ✭ 220 (+547.06%)
Mutual labels:  vapor, server-side-swift

Flash ⚡️

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

This package allows you to display Flash messages between your views.

image

Installation

Add Flash to the package dependencies (in your Package.swift file):

dependencies: [
    ...,
    .package(url: "https://github.com/nodes-vapor/flash.git", from: "4.0.0")
]

as well as to your target (e.g. "App"):

targets: [
    ...
    .target(
        name: "App",
        dependencies: [... "Flash" ...]
    ),
    ...
]

Getting started 🚀

First make sure that you've imported Flash everywhere when needed:

import Flash

Adding the provider

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    try services.register(FlashProvider())
}

Adding the middleware

You can either add the Flash middleware globally by doing:

func configure(_ app: Application) throws {
    app.middleware.use(FlashMiddleware())
}

Alternatively, you can add the middleware to individual route groups where needed:

router.grouped([SessionsMiddleware(driver: app.sessions.driver), 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

In order to render Flash messages, you will need to add the Flash Leaf tag to your application:

func configure(_ app: Application) throws {
    app.leaf.tags["flashes"] = FlashTag()
}

Using Flash messages

With Flash set up, you are now able to redirect while adding a Flash message, given a Request:

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 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

Without using any dependencies, this is how Flash messages could be rendered:

<div class="alerts">
#for(flash in flashes().all):
        Message: #(flash.message)
        Type: #(flash.kind)
    #endfor
</div>

Using the Bootstrap package

The below example uses the Vapor 3 Bootstrap package for generating the alert html.

<div class="alerts">
    #for(flash in flashes().all):
        #bs:alert(flash.bootstrapClass) {
            #(flash.message)
        }
    #endfor
</div>

Add the Flash html to one file and embed it in rest of your views or through a base layout, e.g.: #embed("alerts").

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes.

📄 License

This package is open-sourced software licensed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].