Skip to content

Instantly share code, notes, and snippets.

@shimaore
Created May 27, 2012 20:29
Show Gist options
  • Save shimaore/2815797 to your computer and use it in GitHub Desktop.
Save shimaore/2815797 to your computer and use it in GitHub Desktop.
Proposal for zappajs/zappajs#18
@@ -280,10 +280,38 @@ zappa.app = (func,disable_io,require_css) ->
if typeof arguments[0] isnt 'object'
render.apply @, arguments
else
for k, v of arguments[0]
render.apply @, [k, v]
+ include: (paths) ->
+
+ _end = res.end
+ _write = res.write
+ _header = res.setHeader
+ body = ''
+ res.write = (chunk,encoding) ->
+ body += chunk
+ res.setHeader = (name,value) ->
+ if name isnt 'Content-Length'
+ _header name, value
+
+ completed = 0
+ iterate = ->
+ res.end = (chunk,encoding) ->
+ if chunk?
+ res.write chunk, encoding
+ iterate()
+ if completed < paths.length
+ req.url = paths[completed++]
+ app.handle req, res, ->
+ else
+ res.end = _end
+ res.write = _write
+ res.setHeader = _header
+ res.end body
+ iterate()
+ return
render = (args...) ->
# Adds the app id to the view name so that the monkeypatched
# express.View.exists and express.View.contents can lookup
# this app's inline templates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment