Skip to content
This repository

streaming templates #8

Merged
2 commits merged into from almost 4 years ago

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

Showing 2 unique commits by 1 author.

Sep 28, 2010
Dustin Machi dmachi update html serializer to allow the template to stream aa01b2a
Sep 29, 2010
Dustin Machi dmachi stream templates 6deea47
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 13 additions and 10 deletions. Show diff stats Hide diff stats

  1. +13 10 lib/media/html.js
23 lib/media/html.js
@@ -3,11 +3,11 @@
3 3 */
4 4
5 5 var Media = require("../media").Media,
6   - filesystem = require("perstore/store/filesystem").FileSystem({fsRoot: "templates"}),
  6 + filesystem = require("perstore/store/filesystem").FileSystem({dataFolder: "../templates"}),
7 7 transform = require("../html-transform"),
8 8 Response=require("../jsgi/response").Response,
9   - resolver = require("templify/templify").Resolver;
10   -
  9 + resolver = require("templify/templify").Resolver,
  10 + when = require("promised-io/promise").when;
11 11 var templateEngine = require('templify/templify').TemplateEngine({resolver: resolver, store: filesystem});
12 12
13 13 Media({
@@ -44,22 +44,25 @@ Media({
44 44 object = transform[meta['content-type']](object);
45 45 }
46 46
  47 + //delete any existing content-length headers as the size has changed post conversion/templating
  48 + delete response.headers['content-length'];
47 49
48 50 //TODO update template so we can stream the template rendering
49 51 if (response.status > 400) {
50   - //print("Error Response: " + response.status);
51 52 template = templateEngine.compile("/error/"+response.status);
52   - rendered = template(response);
53 53 }else{
54 54 template = templateEngine.compile(templateId, (mediaParams && mediaParams.template));
55   - rendered = template(object);
56 55 }
57 56
58   - //delete any existing content-length headers as the size has changed post conversion/templating
59   - delete response.headers['content-length'];
60   -
61   - return rendered ? [rendered] : object;
  57 + return {
  58 + forEach: function(write){
  59 + return when(template, function(template){
  60 + template(object).forEach(write);
  61 + })
  62 + }
  63 + }
62 64 },
  65 +
63 66 deserialize: function(inputStream, request){
64 67 throw new Error("not implemented");
65 68 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.