diff --git a/index.js b/index.js index 494f30e..56f9a63 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,22 @@ var _ = require('lodash'); var async = require('async'); // (argument: any) => boolean; -var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && argument.length == 0; }; +var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && !!argument.__templatesSync; }; // (argument: any) => boolean; -var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && argument.length == 1; }; +var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && !!argument.__templatesAsync; }; + +// (argument: Function) => Function; +var asSync = exports.asSync = function(argument) { + if (_.isFunction(argument)) argument.__templatesSync = true; + return argument; +}; + +// (argument: Function) => Function; +var asAsync = exports.asAsync = function(argument) { + if (_.isFunction(argument)) argument.__templatesAsync = true; + return argument; +}; // (data: TData, callback: TCallback) => void; var dataRender = exports.dataRender = function(data, callback) { @@ -14,8 +26,8 @@ var dataRender = exports.dataRender = function(data, callback) { if (data.prototype instanceof Double) data()()._render(callback); else data()._render(callback); } else if (data.__templatesInstance instanceof Content) data.__templatesInstance._render(callback); - else if (data.length == 1) data(callback); - else if (data.length == 0) callback(data()); + else if (data.__templatesAsync) data(function(result) { dataRender(result, callback); }); + else if (data.__templatesSync) dataRender(data(), callback); else callback(data); } else if (_.isObject(data)) { diff --git a/package.json b/package.json index add88b2..55ac92f 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "osws-templates", - "version": "0.2.0", + "version": "0.2.1", "description": "Tools for generating, extending and rendering HTML.", "keywords": [], "author": "Open Source Web Standards (http://osws.github.io/OSWS)", diff --git a/readme.md b/readme.md index a3969cc..de65fa0 100755 --- a/readme.md +++ b/readme.md @@ -1,3 +1,3 @@ -# [OSWS](https://github.com/OSWS) [Templates](https://github.com/OSWS/OSWS-Templates) [0.2.0](https://github.com/OSWS/OSWS-Templates/wiki/0.2.0) +# [OSWS](https://github.com/OSWS) [Templates](https://github.com/OSWS/OSWS-Templates) [0.2.1](https://github.com/OSWS/OSWS-Templates/wiki/0.2.1) [documentation](https://github.com/OSWS/OSWS-Templates/wiki) \ No newline at end of file diff --git a/sources/index.js b/sources/index.js index 3b47021..b1ee49d 100644 --- a/sources/index.js +++ b/sources/index.js @@ -1,8 +1,20 @@ // (argument: any) => boolean; -var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && argument.length == 0; }; +var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && !!argument.__templatesSync; }; // (argument: any) => boolean; -var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && argument.length == 1; }; +var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && !!argument.__templatesAsync; }; + +// (argument: Function) => Function; +var asSync = exports.asSync = function(argument) { + if (_.isFunction(argument)) argument.__templatesSync = true; + return argument; +}; + +// (argument: Function) => Function; +var asAsync = exports.asAsync = function(argument) { + if (_.isFunction(argument)) argument.__templatesAsync = true; + return argument; +}; // (data: TData, callback: TCallback) => void; var dataRender = exports.dataRender = function(data, callback) { @@ -11,8 +23,8 @@ var dataRender = exports.dataRender = function(data, callback) { if (data.prototype instanceof Double) data()()._render(callback); else data()._render(callback); } else if (data.__templatesInstance instanceof Content) data.__templatesInstance._render(callback); - else if (data.length == 1) data(callback); - else if (data.length == 0) callback(data()); + else if (data.__templatesAsync) data(function(result) { dataRender(result, callback); }); + else if (data.__templatesSync) dataRender(data(), callback); else callback(data); } else if (_.isObject(data)) { diff --git a/templates.js b/templates.js index 8c48961..f2f7ee3 100644 --- a/templates.js +++ b/templates.js @@ -1,10 +1,22 @@ define(['exports', 'lodash', 'async'], function(exports, _, async) { // (argument: any) => boolean; -var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && argument.length == 0; }; +var isSync = exports.isSync = function(argument) { return _.isFunction(argument) && !!argument.__templatesSync; }; // (argument: any) => boolean; -var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && argument.length == 1; }; +var isAsync = exports.isAsync = function(argument) { return _.isFunction(argument) && !!argument.__templatesAsync; }; + +// (argument: Function) => Function; +var asSync = exports.asSync = function(argument) { + if (_.isFunction(argument)) argument.__templatesSync = true; + return argument; +}; + +// (argument: Function) => Function; +var asAsync = exports.asAsync = function(argument) { + if (_.isFunction(argument)) argument.__templatesAsync = true; + return argument; +}; // (data: TData, callback: TCallback) => void; var dataRender = exports.dataRender = function(data, callback) { @@ -13,8 +25,8 @@ var dataRender = exports.dataRender = function(data, callback) { if (data.prototype instanceof Double) data()()._render(callback); else data()._render(callback); } else if (data.__templatesInstance instanceof Content) data.__templatesInstance._render(callback); - else if (data.length == 1) data(callback); - else if (data.length == 0) callback(data()); + else if (data.__templatesAsync) data(function(result) { dataRender(result, callback); }); + else if (data.__templatesSync) dataRender(data(), callback); else callback(data); } else if (_.isObject(data)) { diff --git a/templates.min.js b/templates.min.js index 6f9b45f..ecd01c8 100644 --- a/templates.min.js +++ b/templates.min.js @@ -1 +1 @@ -define(["exports","lodash","async"],function(t,e,n){var i=(t.isSync=function(t){return e.isFunction(t)&&0==t.length},t.isAsync=function(t){return e.isFunction(t)&&1==t.length},t.dataRender=function(t,s){if(e.isFunction(t))t.prototype instanceof h?t.prototype instanceof f?t()()._render(s):t()._render(s):t.__templatesInstance instanceof h?t.__templatesInstance._render(s):1==t.length?t(s):s(0==t.length?t():t);else if(e.isObject(t))if(t instanceof h)t._render(s);else{var r;r=e.isArray(t)?[]:{};var o=e.keys(t);n.each(o,function(e,n){i(t[e],function(t){r[e]=t,n()})},function(){s(r)})}else s(t)}),s=t.wrapMethod=function(t,e){return e.__templatesInstance=t,e},r=t.regExpSearch=function(t,e){for(var n=[],i=null;null!=(i=e.exec(t));)i.index===e.lastIndex&&e.lastIndex++,n.push(i);return n},o=t._selectorRegExp=/(\[)|(\])|#([-\w\d]+)|\.([-\w\d]+)|([\w\d-]+)="(['\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]*)"|([\w\d-]+)='(["\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]*)'|([\w\d-]+)=([\w\d-:\\\/\.={}<>%@#$%^&*~`]*)|("['\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]+")|('["\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]+')|([_\w-:\\\/]+)/g,u=t.parseSelector=function(t,n){var i=r(n,o),s=!1;e.each(i,function(e){if(e[1])return void(s=!0);if(e[2])return void(s=!1);if(s){if(e[9])return void(t[e[9]]=e[10]);if(e[7])return void(t[e[7]]=e[8]);if(e[5])return void(t[e[5]]=e[6]);if(e[13])return void(t[e[13]]=null);if(e[12])return void(t[e[12]]=null);if(e[11])return void(t[e[11]]=null)}else{if(e[3])return void(t.id=e[3]);if(e[4])return void(t["class"]?t["class"]+=" "+e[4]:t["class"]=e[4])}})},a=t._stringTemplate=function(t,n,i){i(e.template(t,n))},c=t.Prototype=function(){this._parent=void 0,this._arguments=void 0,this["return"]=function(){return this},this.constructor=function(){},this.extend=function(t){function n(){if(!(this instanceof c)){s=arguments;var r=new n;return r["return"](r)}if(e.isArguments(s)){var o=s;s=void 0}else var o=arguments;this._parent=i,this._arguments=o,e.isFunction(t)&&t.call(this,i),e.isFunction(this.constructor)&&this.constructor.apply(this,o)}var i=this,s=void 0;return n.prototype=i,n}},h=t.Content=(new c).extend(function(t){this._content=void 0,this.prepend=function(){return this._content.unshift.apply(this._content,arguments),this},this.content=function(){return this._content=Array.prototype.slice.call(arguments),this},this.append=function(){return this._content.push.apply(this._content,arguments),this},this._context={},this.render=function(t,n){var i=e.merge(this._context,n);this._render(function(e){a(e,i,t)})},this._render=function(t){i(this._content,function(e){t(e.join(""))})},this.constructor=function(){t.constructor.apply(this),this._content=[],e.isArray(this._parent._content)&&this._content.push.apply(this._content,this._parent._content),this.context={}}}),l=(t.content=h().extend(function(t){this.constructor=function(){t.constructor.apply(this),arguments.length>0&&this.content.apply(this,arguments)}}),t.Tag=h().extend(function(t){this._name=null,this.name=function(t){return this._name=t,this},this._attributes=null,this.attributes=function(t){return e.extend(this._attributes,t),this},this.renderAttributes=function(t){i(this._attributes,function(n){var i="";for(var s in n)i+=e.isNull(n[s])?" "+s:" "+s+'="'+n[s]+'"';t(i)})},this.selector=function(t){return u(this._attributes,t),this},this.constructor=function(){t.constructor.call(this),this._attributes=e.isObject(this._parent._attributes)?e.extend({},this._parent._attributes):{};for(var n in arguments)e.isString(arguments[n])?this.selector(arguments[n]):this.attributes(arguments[n])}})),d=t.Single=l().extend(function(t){this._quotesLeft="<",this._quotesRight="/>",this._render=function(e){var n=this;t._render(function(){n.renderAttributes(function(t){e(n._quotesLeft+n._name+t+n._quotesRight)})})}}),f=t.Double=l().extend(function(t){this._quotesOpenLeft="<",this._quotesOpenRight=">",this._quotesCloseLeft="",this["return"]=function(){var t=this;return s(t,function(){return arguments.length>0?t.content.apply(t,arguments):t})},this._render=function(e){var n=this;t._render.call(n,function(t){n.renderAttributes(function(i){e(n._quotesOpenLeft+n._name+i+n._quotesOpenRight+t+n._quotesCloseLeft+n._name+n._quotesCloseRight)})})}}),p=t.Doctype=l().extend(function(t){this._name="DOCTYPE",this._quotesLeft="",this._render=function(e){var n=this;t._render(function(){n.renderAttributes(function(t){e(n._quotesLeft+n._name+t+n._quotesRight)})})}}),_=t.doctypes={};_.html=p("[html]").extend(),_.transitional=p('[html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]').extend(),_.strict=p('[html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"').extend(),_.frameset=p('[html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"]').extend(),_.basic=p('[html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"]').extend(),_.mobile=p('[html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"]').extend();var m=t._singles=["br","hr","img","input","base","frame","link","meta","style"],g=t.singles={};for(var b in m)g[m[b]]=d().name(m[b]).extend();var v=t._doubles=["html","body","head","h1","h2","h3","h4","h5","h6","hgroup","div","p","address","blockquote","pre","ul","ol","li","dl","dt","dd","fieldset","legend","form","noscript","object","table","thead","tbody","tfoot","tr","td","th","col","colgroup","caption","span","b","big","strong","i","var","cite","em","q","del","s","strike","tt","code","kbd","samp","small","sub","sup","dfn","bdo","abbr","acronym","a","button","textarea","select","option","article","aside","figcaption","figure","footer","header","section","main","nav","menu","audio","video","embed","canvas","output","details","summary","mark","meter","progress","template","comment","title","script"],x=t.doubles={};for(var b in v)x[v[b]]=f()().name(v[b]).extend()}); \ No newline at end of file +define(["exports","lodash","async"],function(t,n,e){var i=(t.isSync=function(t){return n.isFunction(t)&&t.__templatesSync},t.isAsync=function(t){return n.isFunction(t)&&t.__templatesAsync},t.asSync=function(t){return n.isFunction(t)&&(t.__templatesSync=!0),t},t.asAsync=function(t){return n.isFunction(t)&&(t.__templatesAsync=!0),t},t.dataRender=function(t,s){if(n.isFunction(t))t.prototype instanceof h?t.prototype instanceof f?t()()._render(s):t()._render(s):t.__templatesInstance instanceof h?t.__templatesInstance._render(s):t.__templatesAsync?t(function(t){i(t,s)}):t.__templatesSync?i(t(),s):s(t);else if(n.isObject(t))if(t instanceof h)t._render(s);else{var r;r=n.isArray(t)?[]:{};var o=n.keys(t);e.each(o,function(n,e){i(t[n],function(t){r[n]=t,e()})},function(){s(r)})}else s(t)}),s=t.wrapMethod=function(t,n){return n.__templatesInstance=t,n},r=t.regExpSearch=function(t,n){for(var e=[],i=null;null!=(i=n.exec(t));)i.index===n.lastIndex&&n.lastIndex++,e.push(i);return e},o=t._selectorRegExp=/(\[)|(\])|#([-\w\d]+)|\.([-\w\d]+)|([\w\d-]+)="(['\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]*)"|([\w\d-]+)='(["\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]*)'|([\w\d-]+)=([\w\d-:\\\/\.={}<>%@#$%^&*~`]*)|("['\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]+")|('["\w\d\s-:\\\/\.\,\]\[={}<>%@#$%^&*~`]+')|([_\w-:\\\/]+)/g,u=t.parseSelector=function(t,e){var i=r(e,o),s=!1;n.each(i,function(n){if(n[1])return void(s=!0);if(n[2])return void(s=!1);if(s){if(n[9])return void(t[n[9]]=n[10]);if(n[7])return void(t[n[7]]=n[8]);if(n[5])return void(t[n[5]]=n[6]);if(n[13])return void(t[n[13]]=null);if(n[12])return void(t[n[12]]=null);if(n[11])return void(t[n[11]]=null)}else{if(n[3])return void(t.id=n[3]);if(n[4])return void(t["class"]?t["class"]+=" "+n[4]:t["class"]=n[4])}})},c=t._stringTemplate=function(t,e,i){i(n.template(t,e))},a=t.Prototype=function(){this._parent=void 0,this._arguments=void 0,this["return"]=function(){return this},this.constructor=function(){},this.extend=function(t){function e(){if(!(this instanceof a)){s=arguments;var r=new e;return r["return"](r)}if(n.isArguments(s)){var o=s;s=void 0}else var o=arguments;this._parent=i,this._arguments=o,n.isFunction(t)&&t.call(this,i),n.isFunction(this.constructor)&&this.constructor.apply(this,o)}var i=this,s=void 0;return e.prototype=i,e}},h=t.Content=(new a).extend(function(t){this._content=void 0,this.prepend=function(){return this._content.unshift.apply(this._content,arguments),this},this.content=function(){return this._content=Array.prototype.slice.call(arguments),this},this.append=function(){return this._content.push.apply(this._content,arguments),this},this._context={},this.render=function(t,e){var i=n.merge(this._context,e);this._render(function(n){c(n,i,t)})},this._render=function(t){i(this._content,function(n){t(n.join(""))})},this.constructor=function(){t.constructor.apply(this),this._content=[],n.isArray(this._parent._content)&&this._content.push.apply(this._content,this._parent._content),this.context={}}}),l=(t.content=h().extend(function(t){this.constructor=function(){t.constructor.apply(this),arguments.length>0&&this.content.apply(this,arguments)}}),t.Tag=h().extend(function(t){this._name=null,this.name=function(t){return this._name=t,this},this._attributes=null,this.attributes=function(t){return n.extend(this._attributes,t),this},this.renderAttributes=function(t){i(this._attributes,function(e){var i="";for(var s in e)i+=n.isNull(e[s])?" "+s:" "+s+'="'+e[s]+'"';t(i)})},this.selector=function(t){return u(this._attributes,t),this},this.constructor=function(){t.constructor.call(this),this._attributes=n.isObject(this._parent._attributes)?n.extend({},this._parent._attributes):{};for(var e in arguments)n.isString(arguments[e])?this.selector(arguments[e]):this.attributes(arguments[e])}})),d=t.Single=l().extend(function(t){this._quotesLeft="<",this._quotesRight="/>",this._render=function(n){var e=this;t._render(function(){e.renderAttributes(function(t){n(e._quotesLeft+e._name+t+e._quotesRight)})})}}),f=t.Double=l().extend(function(t){this._quotesOpenLeft="<",this._quotesOpenRight=">",this._quotesCloseLeft="",this["return"]=function(){var t=this;return s(t,function(){return arguments.length>0?t.content.apply(t,arguments):t})},this._render=function(n){var e=this;t._render.call(e,function(t){e.renderAttributes(function(i){n(e._quotesOpenLeft+e._name+i+e._quotesOpenRight+t+e._quotesCloseLeft+e._name+e._quotesCloseRight)})})}}),_=t.Doctype=l().extend(function(t){this._name="DOCTYPE",this._quotesLeft="",this._render=function(n){var e=this;t._render(function(){e.renderAttributes(function(t){n(e._quotesLeft+e._name+t+e._quotesRight)})})}}),p=t.doctypes={};p.html=_("[html]").extend(),p.transitional=_('[html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]').extend(),p.strict=_('[html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"').extend(),p.frameset=_('[html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"]').extend(),p.basic=_('[html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"]').extend(),p.mobile=_('[html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"]').extend();var m=t._singles=["br","hr","img","input","base","frame","link","meta","style"],g=t.singles={};for(var b in m)g[m[b]]=d().name(m[b]).extend();var v=t._doubles=["html","body","head","h1","h2","h3","h4","h5","h6","hgroup","div","p","address","blockquote","pre","ul","ol","li","dl","dt","dd","fieldset","legend","form","noscript","object","table","thead","tbody","tfoot","tr","td","th","col","colgroup","caption","span","b","big","strong","i","var","cite","em","q","del","s","strike","tt","code","kbd","samp","small","sub","sup","dfn","bdo","abbr","acronym","a","button","textarea","select","option","article","aside","figcaption","figure","footer","header","section","main","nav","menu","audio","video","embed","canvas","output","details","summary","mark","meter","progress","template","comment","title","script"],x=t.doubles={};for(var b in v)x[v[b]]=f()().name(v[b]).extend()}); \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index fca6034..5c9cd6b 100755 --- a/tests/test.js +++ b/tests/test.js @@ -2,6 +2,8 @@ var Templates = require('../index.js'); var _ = require('lodash'); var assert = require('chai').assert; +var asSync = Templates.asSync; +var asAsync = Templates.asAsync; var Prototype = Templates.Prototype; var Content = Templates.Content; var content = Templates.content; @@ -9,17 +11,18 @@ var Tag = Templates.Tag; var Single = Templates.Single; var Double = Templates.Double; var Doctype = Templates.Doctype; +var div = Templates.doubles.div; describe('OSWS-Templates', function() { it('isSync', function() { - assert.equal(Templates.isSync(function() {}), true); - assert.equal(Templates.isSync(function(callback) {}), false); + assert.equal(Templates.isSync(asSync(function() {})), true); + assert.equal(Templates.isSync(asAsync(function(callback) {})), false); assert.equal(Templates.isSync(function(callback, other) {}), false); assert.equal(Templates.isSync(function(any, args) {}), false); }); it('isAsync', function() { - assert.equal(Templates.isAsync(function() {}), false); - assert.equal(Templates.isAsync(function(callback) {}), true); + assert.equal(Templates.isAsync(asSync(function() {})), false); + assert.equal(Templates.isAsync(asAsync(function(callback) {})), true); assert.equal(Templates.isAsync(function(callback, other) {}), false); assert.equal(Templates.isAsync(function(any, args) {}), false); }); @@ -28,15 +31,18 @@ describe('OSWS-Templates', function() { Templates.dataRender('string', function(result) { assert.equal(result, 'string'); done(); }); }); it('TSync', function(done) { - Templates.dataRender(function() { return 'string'; }, function(result) { assert.equal(result, 'string'); done(); }); + Templates.dataRender(asSync(function() { return 'string'; }), function(result) { assert.equal(result, 'string'); done(); }); }); it('TAsync', function(done) { - Templates.dataRender(function(callback) { callback('string'); }, function(result) { assert.equal(result, 'string'); done(); }); + Templates.dataRender(asAsync(function(callback) { callback('string'); }), function(result) { assert.equal(result, 'string'); done(); }); }); it('Function', function(done) { var bug = function(a, b, c) { return 'bug' }; Templates.dataRender(bug, function(result) { assert.equal(result, bug); done(); }); }); + it('Function with Element', function(done) { + Templates.dataRender(asSync(function() { return div; }), function(result) { assert.equal(result, '
'); done(); }); + }); it('Content', function(done) { var Temp = content().content(1).extend(); Templates.dataRender(Temp, function(result) { assert.equal(result, 1); done(); }); @@ -45,7 +51,7 @@ describe('OSWS-Templates', function() { Templates.dataRender({ key: 'value' }, function(result) { assert.equal(result.key, 'value'); done(); }); }); it('Array', function(done) { - Templates.dataRender(['key', function() { return 'value'; }], function(result) { assert.equal(result[1], 'value'); done(); }); + Templates.dataRender(['key', asSync(function() { return 'value'; })], function(result) { assert.equal(result[1], 'value'); done(); }); }); }); describe('parseSelector', function() { @@ -95,8 +101,8 @@ describe('OSWS-Templates', function() { it('render', function(done) { var el = Content().content( '1', - function() { return '<%= n2 %>'; }, - function(callback) { setTimeout(function() { callback('<%= n3 %>'); }, 150); }, + asSync(function() { return '<%= n2 %>'; }), + asAsync(function(callback) { setTimeout(function() { callback('<%= n3 %>'); }, 150); }), Content().content('<%= n4 %>') ); el.render(function(result) { @@ -107,8 +113,8 @@ describe('OSWS-Templates', function() { it('multi-layered', function(done) { var el = Content().content( '1', - function() { return '<%= n2 %>'; }, - function(callback) { setTimeout(function() { callback('<%= n3.val %>'); }, 150); }, + asSync(function() { return '<%= n2 %>'; }), + asAsync(function(callback) { setTimeout(function() { callback('<%= n3.val %>'); }, 150); }), Content().content('<%= n4 %>') ); el.render(function(result) {