Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

streaming templates #8

Merged
2 commits merged into from

2 participants

Dustin Machi Kris Zyp
Dustin Machi

Another update to html.js. It now expects the compiled template function to return a forEach able to allow the template rendering to stream. It should be lazy compiling (we need to discuss how to cache this appropriately) and rendering in stream now.

Kris Zyp
Owner

It would be great to utilize the templating in the persevere example wiki app. Right now there is a simple hack for a template, but it would be great to get that updated to use your real templating stuff.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2010
  1. Dustin Machi
Commits on Sep 29, 2010
  1. Dustin Machi

    stream templates

    dmachi authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 10 deletions.
  1. +13 −10 lib/media/html.js
23 lib/media/html.js
View
@@ -3,11 +3,11 @@
*/
var Media = require("../media").Media,
- filesystem = require("perstore/store/filesystem").FileSystem({fsRoot: "templates"}),
+ filesystem = require("perstore/store/filesystem").FileSystem({dataFolder: "../templates"}),
transform = require("../html-transform"),
Response=require("../jsgi/response").Response,
- resolver = require("templify/templify").Resolver;
-
+ resolver = require("templify/templify").Resolver,
+ when = require("promised-io/promise").when;
var templateEngine = require('templify/templify').TemplateEngine({resolver: resolver, store: filesystem});
Media({
@@ -44,22 +44,25 @@ Media({
object = transform[meta['content-type']](object);
}
+ //delete any existing content-length headers as the size has changed post conversion/templating
+ delete response.headers['content-length'];
//TODO update template so we can stream the template rendering
if (response.status > 400) {
- //print("Error Response: " + response.status);
template = templateEngine.compile("/error/"+response.status);
- rendered = template(response);
}else{
template = templateEngine.compile(templateId, (mediaParams && mediaParams.template));
- rendered = template(object);
}
- //delete any existing content-length headers as the size has changed post conversion/templating
- delete response.headers['content-length'];
-
- return rendered ? [rendered] : object;
+ return {
+ forEach: function(write){
+ return when(template, function(template){
+ template(object).forEach(write);
+ })
+ }
+ }
},
+
deserialize: function(inputStream, request){
throw new Error("not implemented");
}
Something went wrong with that request. Please try again.