Guest User

Untitled

a guest
Nov 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. require('zappajs') ->
  2. @use 'zappa'
  3. @enable 'default layout'
  4.  
  5. @get '/': ->
  6. foo = 'bar'
  7. @render 'index', foo: foo, hardcode: { coffee: export_params }
  8.  
  9. @view index: ->
  10. @scripts = ['/zappa/jquery']
  11. coffee ->
  12. $(document).ready ->
  13. alert params.foo
  14.  
  15. # Embed the @render params into window.params (aka `params` since
  16. # window is the client-side Javascript context).
  17.  
  18. export_params = (coffee) ->
  19. text "<script> window.params = {};"
  20. for name, value of @
  21. try text """
  22. window.params[#{JSON.stringify name}] = #{JSON.stringify value};
  23. """
  24. text "</script>"
  25. coffeescript coffee
Add Comment
Please, Sign In to add comment