Comparing version 0.0.1 to 0.0.2
@@ -15,2 +15,4 @@ /* jshint node:true */ | ||
this.maxDepth = config.maxDepth || 3; | ||
this.cache = config.cache || new Cache(config); | ||
@@ -22,11 +24,19 @@ this.dataProvider = config.dataProvider || new DataProvider(config); | ||
ESI.prototype.processParsed = function(parsedHtml, options) { | ||
ESI.prototype.processParsed = function(parsedHtml, options, state) { | ||
var self = this; | ||
options = options || {}; | ||
state = state || {}; | ||
state.currentDepth = state.currentDepth || 0; | ||
return new Promise(function (resolve, reject) { | ||
var subtasks = []; | ||
var subtasks = [], | ||
maxDepthReached = state.currentDepth > self.maxDepth; | ||
self.walkTree(function (subtree) { | ||
if (subtree.nodeName === 'esi:include') { | ||
if (maxDepthReached) { | ||
if (subtree.nodeName.indexOf('esi:') === 0) { | ||
subtasks.push(self.replaceWithBlank(subtree)); | ||
} | ||
} else if (subtree.nodeName === 'esi:include') { | ||
subtasks.push(self.include(subtree, options)); | ||
@@ -38,3 +48,4 @@ } | ||
if (self.hasIncludeTag(parsedHtml)) { | ||
self.processParsed(parsedHtml, options).then(function (result) { | ||
state.currentDepth++; | ||
self.processParsed(parsedHtml, options, state).then(function (result) { | ||
resolve(result); | ||
@@ -147,4 +158,17 @@ }); | ||
}); | ||
}; | ||
ESI.prototype.replaceWithBlank = function(original) { | ||
var childNodes = original.parentNode.childNodes; | ||
childNodes.forEach(function (childNode, i) { | ||
if (childNode === original) { | ||
// remove node | ||
childNodes.splice(i, 1); | ||
} | ||
}); | ||
}; | ||
module.exports = ESI; |
{ | ||
"name": "nodesi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "ESI: the good parts in node.js", | ||
@@ -5,0 +5,0 @@ "main": "esi.js", |
@@ -380,3 +380,3 @@ /* jshint node:true */ | ||
res.end('<esi:include src="http://localhost:' + port + '/second"></esi:include>'); | ||
} else if (req.url == '/second') { | ||
} else if (req.url === '/second') { | ||
res.end('<esi:include src="http://localhost:' + port + '/third"></esi:include>'); | ||
@@ -401,20 +401,22 @@ } else { | ||
//it('should set max fetch limit for recursive components', function (done) { | ||
// // given | ||
// server.addListener('request', function (req, res) { | ||
// res.writeHead(200, {'Content-Type': 'text/html'}); | ||
// res.end('<esi:include src="http://localhost:' + port + '"></esi:include>') | ||
// }); | ||
// | ||
// var html = '<section><esi:include src="http://localhost:' + port + '"></esi:include></section>'; | ||
// | ||
// // when | ||
// var processed = new ESI().process(html); | ||
// | ||
// // then | ||
// processed.then(function (response) { | ||
// assert.equal(response, '<section></section>'); | ||
// done(); | ||
// }).catch(done); | ||
//}); | ||
it('should set max fetch limit for recursive components', function (done) { | ||
// given | ||
server.addListener('request', function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'text/html'}); | ||
res.end('<esi:include src="http://localhost:' + port + '"></esi:include>'); | ||
}); | ||
var html = '<section><esi:include src="http://localhost:' + port + '"></esi:include></section>'; | ||
// when | ||
var processed = new ESI({ | ||
maxDepth: 5 | ||
}).process(html); | ||
// then | ||
processed.then(function (response) { | ||
assert.equal(response, '<section></section>'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
@@ -421,0 +423,0 @@ it('should pass specified headers to server', function (done) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26958
702