Open rockymeza opened 13 years ago
They were never intended to be, but this is indeed an issue that needs to be sorted out for the next versions.
Express has its own kinda different concept of helpers and how to harmonize it with zappa is still a big question to me. In express helpers are actually only available to views. There are static helpers, which are to views in express what def is to handlers in zappa (they don't have access to anything besides their params). There are also dynamic helpers, which are more like zappa's helpers, having access to request handling stuff, but they're only for views. Then there's route middleware, which is the closest thing in express to zappa's helpers, but stuck to being executed before the route.
Then there's sinatra, from which all the inspiration for both comes, and its helpers are available to both handlers and views, but they don't have access to any request handling stuff directly, only their parameters.
We could just keep zappa's own current helpers and defs implementation and extend it to also be available to views, but the next version of zappa is all about being more harmonized with express, and using its implementations whenever possible. Besides, I'm not sure having these suckers automatically taking up namespace in both handlers and views is a good idea. I'm of the impression we either want each helper for the handlers or the views. What do you think?
As long as you're tracking the edge of coffeekup within your node_modules/zappa/node_modules/coffeekup
dir, you can now pass in helpers to your renderer:
def hardcode:
a: 'asdf'
get '/': ->
@a = hardcode.a
render 'index', {hardcode}
view index: ->
a # 'asdf'
@a # 'asdf'
They are available in the get and post type functions.
In order to get anything into a view, one has to pass it in explicitly from the get-type function to the view.