0.2.1-1 • Published 13 years ago
onion.utils v0.2.1-1
Onion Utils
Some useful utilities for onion.
Filter
The filter
middleware can be used to run a middleware under certain
conditions. The first argument of filter
has to be a rule
which is a
function that returns a boolean value. If the function returns true
the
middleware will be executed, otherwise it will be left out.
Example
Simple example. The Onion should return 42
if, and only if the given
number is 42
. Otherwise it should return 0
.
Onion = require 'onion'
utils = require 'onion.utils'
filter = utils.filter
onion = new Onion
rule = (x) ->
x is 42
middleware = (x) ->
x
skin = filter rule, middleware
onion.stack "foo", skin
onion.innermost = ->
return 0
console.log onion.peelFor "foo", 23
console.log onion.peelFor "foo", 42
0
42