Skip to content

Instantly share code, notes, and snippets.

@shimaore
Created September 20, 2011 07:42
Show Gist options
  • Save shimaore/1228579 to your computer and use it in GitHub Desktop.
Save shimaore/1228579 to your computer and use it in GitHub Desktop.
Setting 'noclobber' allows @ to contain the data while the zappa context is passed as an argument. Setting 'dataparam' keeps @ as the context while the data is passed as an argument.
diff -ru mauricemach-zappa-ac57545//src/zappa.coffee zappa-noclobber//src/zappa.coffee
--- mauricemach-zappa-ac57545//src/zappa.coffee 2011-09-17 03:12:51.000000000 +0200
+++ zappa-noclobber//src/zappa.coffee 2011-09-20 10:42:15.000000000 +0200
@@ -285,12 +285,19 @@
names = []
names.push k for k, v of ctx
+ data = [req.query, req.params, req.body]
+
if app.settings['autoimport']
# Imports input vars to ctx. Does NOT overwrite existing variables.
- copy_data_to ctx, [req.query, req.params, req.body]
+ copy_data_to ctx, data
# Go!
- result = r.handler.apply(ctx, [ctx])
+ if app.settings['noclobber']
+ result = r.handler.apply(data, [ctx])
+ else if app.settings['dataparam']
+ result = r.handler.apply(ctx, [data])
+ else
+ result = r.handler.apply(ctx, [ctx])
res.contentType(r.contentType) if r.contentType?
if typeof result is 'string' then res.send result
@@ -342,7 +349,12 @@
ctx.data = data
if app.settings['autoimport']
copy_data_to ctx, [data]
- h.apply(ctx, [ctx])
+ if app.settings['noclobber']
+ h.apply(data, [ctx])
+ else if app.settings ['dataparam']
+ h.apply(ctx, [data])
+ else
+ h.apply(ctx, [ctx])
# Go!
func.apply(context, [context])
--- mauricemach-zappa-ac57545//src/zappa.coffee 2011-09-17 03:12:51.000000000 +0200
+++ zappa-noclobber//src/zappa.coffee 2011-09-20 09:58:48.000000000 +0200
@@ -290,7 +290,12 @@
copy_data_to ctx, [req.query, req.params, req.body]
# Go!
- result = r.handler.apply(ctx, [ctx])
+ if app.settings['noclobber']
+ result = r.handler.apply(data, [ctx])
+ else if app.settings['dataparam']
+ result = r.handler.apply(ctx, [data])
+ else
+ result = r.handler.apply(ctx, [ctx])
res.contentType(r.contentType) if r.contentType?
if typeof result is 'string' then res.send result
@@ -342,7 +347,12 @@
ctx.data = data
if app.settings['autoimport']
copy_data_to ctx, [data]
- h.apply(ctx, [ctx])
+ if app.settings['noclobber']
+ h.apply(data, [ctx])
+ else if app.settings ['dataparam']
+ h.apply(ctx, [data])
+ else
+ h.apply(ctx, [ctx])
# Go!
func.apply(context, [context])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment