Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers and defs are not availabe in views #38

Open
rockymeza opened this issue May 7, 2011 · 2 comments
Open

helpers and defs are not availabe in views #38

rockymeza opened this issue May 7, 2011 · 2 comments

Comments

@rockymeza
Copy link

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.

def a: 'asdf'

get '/': ->
  @a = a
  render 'index'

view index: ->
  a # undefined
  @a # asdf
@mauricemach
Copy link
Owner

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?

@smathy
Copy link
Contributor

smathy commented Aug 23, 2011

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants