raptor-dust
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -1,2 +0,2 @@ | ||
var DustRenderContext = require('./DustRenderContext'); | ||
var DustAsyncWriter = require('./DustAsyncWriter'); | ||
@@ -6,6 +6,8 @@ function invokeRenderer(renderFunc, dustChunk, dustContext, dustBodies, params, buildInput) { | ||
var renderContext = new DustRenderContext(dustChunk, dustContext, attributes); | ||
var dustAsyncWriter = new DustAsyncWriter(dustChunk, dustContext, attributes); | ||
// Keep a reference to the underlying stream that we are writing to (if available) | ||
renderContext.stream = attributes.stream; | ||
if (attributes.stream) { | ||
dustAsyncWriter.stream = attributes.stream; | ||
} | ||
@@ -15,3 +17,3 @@ params = params || {}; | ||
if (buildInput) { | ||
params = buildInput(dustChunk, dustContext, dustBodies, params, renderContext); | ||
params = buildInput(dustChunk, dustContext, dustBodies, params, dustAsyncWriter); | ||
} else { | ||
@@ -30,4 +32,7 @@ for (var k in params) { | ||
renderFunc(params, renderContext); | ||
return renderContext._dustChunk; | ||
renderFunc(params, dustAsyncWriter); | ||
dustAsyncWriter.end(); | ||
return dustAsyncWriter._dustChunk; | ||
} | ||
@@ -34,0 +39,0 @@ |
@@ -38,3 +38,3 @@ { | ||
"main": "lib/raptor-dust.js", | ||
"version": "1.1.4" | ||
"version": "1.1.5" | ||
} |
@@ -29,3 +29,3 @@ 'use strict'; | ||
asyncOut.end(); | ||
}, 1000); | ||
}, 200); | ||
}); | ||
@@ -67,3 +67,42 @@ | ||
it('should allow dust.stream() to be used with an existing async writer', function(done) { | ||
var out = require('async-writer').create(); | ||
var asyncOut = out.beginAsync(); | ||
var output = ''; | ||
out.on('finish', function() { | ||
expect(output).to.equal('Hello Async'); | ||
done(); | ||
}); | ||
var templatePath = require.resolve('./pages/async-test.dust'); | ||
var templateData = {}; | ||
var attributes = out.attributes; | ||
var base = attributes.dustBase; | ||
if (!base) { | ||
// Make sure all Dust context objects use the "attributes" | ||
// as their global so that attributes are carried across | ||
// rendering calls | ||
attributes.stream = out.stream; | ||
base = attributes.dustBase = dust.makeBase(attributes); | ||
} | ||
if (out.dustContext) { | ||
base = out.dustContext.push(base); | ||
} | ||
templateData = base.push(templateData); | ||
templateData.templateName = templatePath; | ||
dust.stream(templatePath, templateData) | ||
.on('data', function(data) { | ||
output += data; | ||
}) | ||
.on('end', function() { | ||
asyncOut.end(); | ||
}); | ||
out.end(); | ||
}); | ||
}); |
21962
215