Comparing version 0.3.0 to 0.3.1
96
index.js
@@ -11,13 +11,13 @@ /** | ||
var tags = [ | ||
"script", | ||
"style", | ||
"html", | ||
"body", | ||
"require", | ||
"uri", | ||
"widget", | ||
"head", | ||
"feature", | ||
"featureelse", | ||
"spage" | ||
'script', | ||
'style', | ||
'html', | ||
'body', | ||
'require', | ||
'uri', | ||
'widget', | ||
'head', | ||
'feature', | ||
'featureelse', | ||
'spage' | ||
]; | ||
@@ -27,2 +27,31 @@ | ||
var EngineStream = function (swig, view, locals) { | ||
this.swig = swig; | ||
this.view = view; | ||
this.locals = locals; | ||
this.reading = false; | ||
Readable.call(this); | ||
}; | ||
util.inherits(EngineStream, Readable); | ||
EngineStream.prototype._read = function () { | ||
var self = this; | ||
// var state = self._readableState; | ||
if (this.reading) { | ||
return; | ||
} | ||
this.reading = true; | ||
debuglog('start render [%s]', this.view); | ||
this.swig.renderFile(this.view, this.locals, function (error, output) { | ||
if (error) { | ||
debuglog('render [%s] failed', self.view); | ||
return self.emit('error', error); | ||
} | ||
debuglog('render [%s] succ', self.view); | ||
self.push(output); | ||
self.push(null); | ||
}); | ||
}; | ||
/** | ||
@@ -80,31 +109,3 @@ * Opitions 说明 | ||
var EngineStream = function (swig, view, locals) { | ||
this.swig = swig; | ||
this.view = view; | ||
this.locals = locals; | ||
this.reading = false; | ||
Readable.call(this); | ||
}; | ||
util.inherits(EngineStream, Readable); | ||
EngineStream.prototype._read = function () { | ||
var self = this; | ||
var state = self._readableState; | ||
if (this.reading) { | ||
return; | ||
} | ||
this.reading = true; | ||
debuglog('start render [%s]', this.view); | ||
this.swig.renderFile(this.view, this.locals, function (error, output) { | ||
if (error) { | ||
debuglog('render [%s] failed', self.view); | ||
return self.emit('error', error); | ||
} | ||
debuglog('render [%s] succ', self.view); | ||
self.push(output); | ||
self.push(null); | ||
}); | ||
}; | ||
// 扩展swig内置函数,用于提供bigpipe支持 | ||
@@ -122,4 +123,3 @@ Swig.prototype._w = Swig.prototype._widget = function (layer, id, attr, options) { | ||
var container = attr['container'] || attr['for']; | ||
layer.addPagelet({ | ||
var pageletOptions = { | ||
container: container, | ||
@@ -133,3 +133,2 @@ model: attr.model, | ||
viewId: id, | ||
compiled: function (locals) { | ||
@@ -140,6 +139,15 @@ var fn = self.compileFile(pathname, options); | ||
} | ||
}); | ||
}; | ||
return container ? '' : '<div id="' + attr.id + '"></div>'; | ||
if (layer.bigpipe.isSpiderMode) { | ||
var syncPagelet = new layer.bigpipe.Pagelet(pageletOptions); | ||
syncPagelet.start(layer.bigpipe.pageletData[attr.id], true); | ||
return container ? syncPagelet.html : '<div id="' + attr.id + '"> ' + syncPagelet.html + '</div>'; | ||
} | ||
else { | ||
container = attr['container'] || attr['for']; | ||
layer.addPagelet(pageletOptions); | ||
return container ? '' : '<div id="' + attr.id + '"></div>'; | ||
} | ||
}; | ||
}; |
{ | ||
"name": "yog-swig", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "custom swig template, add some tag or filter ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
23824
606