vol4ok/hogan-express — pull request #16 by FabledWeb (2013-10-03 06:07:21+00:00)
Title: READY: add better lambda/filter support

Currently, in order to implement filters/lambdas you have to know and do a lot. You have to:
1. include hogan.js in your app
2. know the strange "lambda factory"-ish style of using a function that returns a function
3. realize that what you get as "text" in the function call is the pre-rendered/compiled template snippet
4. know the hogan.js API for compiling and rendering the template snippet
5. pass around variables/context (especially when trying to operate on objects within an array loop)

This pull request encapsulates all of that for you so you can simply define your lambdas as functions that should be run on the processed template snippet. For example:

```coffeescript
app.get '/', (req,res)->

res.locals = myDefaultLabel: "oops" # here to show a little of how scoping works

res.render 'template',
message: 'This is a message. HERE.'
mylist: [{label: "one", num: 1},{label: "two", num: 2},{num: 3}]

lambdas:
lowercase: (text) ->
return text.toLowerCase()
reverseString: (text) ->
return text.split("").reverse().join("")
```

template:

```html

Lowercase {{message}}: {{#lambdas.lowercase}}{{message}}{{/lambdas.lowercase}}

{{#mylist}}

{{num}}: {{label}} is {{#reverseString}}{{label}}{{#reverseString}} in reverse.

{{/mylist}}

```

rendered html:

```html

Lowercase This is a message. HERE.: this is a message. here.

1: one is eno in reverse.

2: two is owt in reverse.

3: oops is spoo in reverse.

```

You can see this in action in the example app. I also wrote some tests (mocha+supertest) that exercise this new feature within the app. README was also updated to reflect the new feature.