Giter Club home page Giter Club logo

flash's Introduction

Flash

Language Build Status codecov GitHub license

This package is to ease using flash message between your views

image

#Installation

Update your Package.swift file.

.Package(url: "https://github.com/nodes-vapor/flash", majorVersion: 0)

main.swift

import Flash

And add middleware either global

drop.middleware.append(FlashMiddleware())

or just to your route group

drop.group(FlashMiddleware()) { group in
   // Routes
}

Usages

Apply flash on a response, which will be shown on next request

return Response(redirect: "/admin/users").flash(.error, "Failed to save user")
return Response(redirect: "/admin/users").flash(.success, "Successfuly saved")
return Response(redirect: "/admin/users").flash(.warning, "Updated user")
return Response(redirect: "/admin/users").flash(.info, "Email sent")

Misc functions

// Add to request by string
try request.flash.add(custom: String, message: String)

// Add to request by enum
try request.flash.add(type: Helper.FlashType, message: String)

// Clear all flashes
try request.flash.clear()

// Show current flash messages again in next request
try request.flash.refresh()

Example of HTML

<!--Error-->
#if(request.storage._flash.error) {
    <div class="alert alert-danger alert-dismissible fade in to-be-animated-in" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        <span class="fa fa-exclamation-circle"></span>
        #(request.storage._flash.error)
    </div>
}

<!--Success-->
#if(request.storage._flash.success) {
<div class="alert alert-success alert-dismissible fade in to-be-animated-in" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <span class="fa fa-check-circle"></span>
    #(request.storage._flash.success)
</div>
}

<!--Warning-->
#if(request.storage._flash.warning) {
<div class="alert alert-warning alert-dismissible fade in to-be-animated-in" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    #(request.storage._flash.warning)
</div>
}

<!--Info-->
#if(request.storage._flash.info) {
<div class="alert alert-info alert-dismissible fade in to-be-animated-in" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    #(request.storage._flash.info)
</div>
}

Add the flash html to one file and embed it in rest of your views or through a base layout fx: #embed("Layout/Partials/Elements/alerts") or fx: #extend("Layout/Base-Layout")

flash's People

Contributors

casperhr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.