0.3.1 • Published 8 years ago

one-flash v0.3.1

Weekly downloads
41
License
-
Repository
github
Last release
8 years ago

one-flash

NPM version Dependency Status Gittip

A flash implementation for Express that goes away after the first navigation.

Usage

npm install one-flash --save

Backend

add it as middleware AFTER session() in your app.js

app.use(session());
app.use(require('one-flash'));

In routes (or any handler)

router.get('/flash', function(req, res) {
    req.oneFlash('warning', 'hello redirect');
    res.redirect('/');
});

router.get('/flashrender', function(req, res) {
    req.oneFlash('hello render'); // notice how type is not required. It will default to 'info'.
    res.render('index', {
        title: 'Index - TEST'
    });
});

Frontend

(Nunjucks + bootstrap.js 3.x)

  {% for message in flash %}
  <div class="alert alert-{{ message.type }} alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    {{ message.message }}
  </div>
  {% endfor %}

API

oneFlash adds a property to locals called "flash", its value is an array of "flash" objects.

res.locals.flash = [
  {
    type: 'info',
    message: 'hello flash',
  }
];

Tests

The entire middleware is very small, and im not sure how to do automated test redirects without a complex Selenium setup. You should know in about two seconds if it doesnt work. Just copy/paste the router samples above and test it.

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago