dt-stream
Version:
Δt stream adapter - async & dynamic templating engine
1 lines • 13.5 kB
JavaScript
!function(){var e=function(t,r){var n=e.resolve(t,r||"/"),i=e.modules[n];if(!i)throw new Error("Failed to resolve module "+t+", tried "+n);var s=i._cached?i._cached:i();return s};e.paths=[],e.modules={},e.extensions=[".js",".coffee"],e._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},e.resolve=function(){return function(t,r){function n(t){if(e.modules[t])return t;for(var r=0;r<e.extensions.length;r++){var n=e.extensions[r];if(e.modules[t+n])return t+n}}function i(t){t=t.replace(/\/+$/,"");var r=t+"/package.json";if(e.modules[r]){var i=e.modules[r](),s=i.browserify;if("object"==typeof s&&s.main){var o=n(u.resolve(t,s.main));if(o)return o}else if("string"==typeof s){var o=n(u.resolve(t,s));if(o)return o}else if(i.main){var o=n(u.resolve(t,i.main));if(o)return o}}return n(t+"/index")}function s(e,t){for(var r=o(t),s=0;s<r.length;s++){var u=r[s],a=n(u+"/"+e);if(a)return a;var l=i(u+"/"+e);if(l)return l}var a=n(e);return a?a:void 0}function o(e){var t;t="/"===e?[""]:u.normalize(e).split("/");for(var r=[],n=t.length-1;n>=0;n--)if("node_modules"!==t[n]){var i=t.slice(0,n+1).join("/")+"/node_modules";r.push(i)}return r}if(r||(r="/"),e._core[t])return t;var u=e.modules.path(),a=r||".";if(t.match(/^(?:\.\.?\/|\/)/)){var l=n(u.resolve(a,t))||i(u.resolve(a,t));if(l)return l}var h=s(t,a);if(h)return h;throw new Error("Cannot find module '"+t+"'")}}(),e.alias=function(r,n){var i=e.modules.path(),s=null;try{s=e.resolve(r+"/package.json","/")}catch(o){s=e.resolve(r,"/")}for(var u=i.dirname(s),a=t(e.modules),l=0;l<a.length;l++){var h=a[l];if(h.slice(0,u.length+1)===u+"/"){var c=h.slice(u.length);e.modules[n+c]=e.modules[u+c]}else h===u&&(e.modules[n]=e.modules[u])}},e.define=function(t,r){var n=e._core[t]?"":e.modules.path().dirname(t),i=function(t){return e(t,n)};i.resolve=function(t){return e.resolve(t,n)},i.modules=e.modules;var s={exports:{}};e.modules[t]=function(){return r.call(s.exports,i,s,s.exports,n,t),e.modules[t]._cached=s.exports,s.exports}};var t=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};"undefined"==typeof process&&(process={}),process.nextTick||(process.nextTick=function(e){setTimeout(e,0)}),process.title||(process.title="browser"),process.binding||(process.binding=function(t){if("evals"===t)return e("vm");throw new Error("No such module")}),process.cwd||(process.cwd=function(){return"."}),e.define("path",function(e,t,r){function n(e,t){for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}function i(e,t){for(var r=0,n=e.length;n>=0;n--){var i=e[n];"."==i?e.splice(n,1):".."===i?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var s=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;r.resolve=function(){for(var e="",t=!1,r=arguments.length;r>=-1&&!t;r--){var s=r>=0?arguments[r]:process.cwd();"string"==typeof s&&s&&(e=s+"/"+e,t="/"===s.charAt(0))}return e=i(n(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."},r.normalize=function(e){var t="/"===e.charAt(0),r="/"===e.slice(-1);return e=i(n(e.split("/"),function(e){return!!e}),!t).join("/"),e||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e},r.join=function(){var e=Array.prototype.slice.call(arguments,0);return r.normalize(n(e,function(e){return e&&"string"==typeof e}).join("/"))},r.dirname=function(e){var t=s.exec(e)[1]||"",r=!1;return t?1===t.length||r&&t.length<=3&&":"===t.charAt(1)?t:t.substring(0,t.length-1):"."},r.basename=function(e,t){var r=s.exec(e)[2]||"";return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r},r.extname=function(e){return s.exec(e)[3]||""}}),e.define("/dt-stream.js",function(e,t){!function(){var r,n,i,s,o,u,a,l,h,c=function(e,t){return function(){return e.apply(t,arguments)}},d={}.hasOwnProperty,p=function(e,t){function r(){this.constructor=e}for(var n in t)d.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};s=e("stream").Stream,i=e("ordered-emitter"),h=e("./util"),a=h.prettify,u=h.attrStr,r=["add","close","end","remove","attr","text","raw","data"],n=function(){function e(e,t,r){var n,s,o,u,a,l,h=this;this.stream=e,this.parent=r,this["delete"]=c(this["delete"],this),this.release=c(this.release,this),this.do_job=c(this.do_job,this),this.order=new i({span:!0}),this.released=!1,this.isnext=null!=this.parent?!1:!0,this.children=0,this.order.on("entry",this.do_job),this.isnext||(null!=(s=this.parent)&&s._stream.write(function(){return t.isempty&&t.closed!==!0||h.release(),h.isnext=!0}),n=null!=(o=null!=(u=this.parent)?u._stream.children:void 0)?o:-1,null!=(a=this.parent)&&a._stream.children++,t.ready(function(){var e;return null!=(e=this.parent)?e._stream.emit("close scope",{order:n+1}):void 0}),null!=(l=this.parent)&&l._stream.release())}return e.prototype.do_job=function(e){var t;return(t=e.job)?this.stream.paused?this.stream.queue.push(t):t():void 0},e.prototype.emit=function(){var e;return null!=(e=this.order)?e.emit.apply(e,arguments):void 0},e.prototype.write=function(e){var t;return t={job:e,order:++this.children},this.stream.paused?(this.children>1&&this.isnext&&this.stream.queue.push(this.release),this.stream.queue.push(this.emit.bind(this,"entry",t))):(this.children>1&&this.isnext&&this.release(),this.emit("entry",t))},e.prototype.release=function(){return this.released?void 0:(this.emit("open scope",{order:0}),this.released=!0)},e.prototype["delete"]=function(){return this.order.removeAllListeners(),this.order.reset(),this.order.clear(),delete this.parent,delete this.order},e}(),o=function(e){function t(e,r){var n,i,s,o,u;this.template=e,null==r&&(r={}),this.close=c(this.close,this),t.__super__.constructor.call(this),this.builder=null!=(i=this.template.xml)?i:this.template,null==(s=(n=this.builder).apdaters)&&(n.apdaters={}),this.builder.apdaters.stream=this,this.autoremove=null!=(o=r.autoremove)?o:!0,this.setEncoding(null!=(u=r.encoding)?u:"utf8"),this.opened_tags=0,this.readable=!0,this.paused=!1,this.queue=[],r.stream&&this.pipe(r.stream),this.initialize()}return p(t,e),t.prototype.initialize=function(){return this.template.stream=this,this.builder._stream=new n(this,this.builder),this.listen(),this.template.register("ready",this.approve_ready)},t.prototype.approve_ready=function(e,t){return e._stream_ready===!0?t(e):e._stream_ready=function(){return t(e)}},t.prototype.listen=function(){var e=this;return r.forEach(function(t){return e.template.on(t,e["on"+t].bind(e))})},t.prototype.write=function(e){return e?(this.paused&&this.emit("error","write data while paused"),this.emit("data",e)):void 0},t.prototype.close=function(){return this.builder.closed=!0,this.readable=!1,this.emit("end"),this.emit("close")},t.prototype.setEncoding=function(e){this.encoding=e},t.prototype.pause=function(){return this.paused?void 0:(this.paused=!0,this.emit("pause"),this.template.emit("pause"))},t.prototype.resume=function(){var e;for(this.paused&&(this.emit("resume"),this.template.emit("resume"),this.paused=!1);!this.paused&&this.queue.length;)"function"==typeof(e=this.queue.shift())&&e();null==this.closed||this.queue.length||("function"==typeof this.closed&&this.closed(),this.closed=!0)},t.prototype.onadd=function(e,t){var r=this;return e.writable?(t._stream=new n(this,t,e),this.opened_tags++,t._stream.write(function(){return t!==t.builder?t.isempty&&t.closed===!0?r.write(a(t,"<"+t.name+u(t.attrs)+"/>")):r.write(a(t,"<"+t.name+u(t.attrs)+">")):void 0}),this.autoremove?t.ready(function(){return"removed"===t.closed?r.onremove(t):t.remove()}):void 0):(console.warn("creating "+t.toString()+" in closed "+e.toString()+" omitted"),void 0)},t.prototype.onremove=function(e){return null!=e._stream?(this.opened_tags--,0!==this.opened_tags||"pending"!==this.builder.closed||this.queue.length||("function"==typeof this.closed&&this.closed(),this.closed=!0),e._stream.write(function(){return e._stream["delete"](),delete e._stream})):void 0},t.prototype.onclose=function(e){var t,r=this;return null!=(t=e._stream)?t.write(function(){return e.isempty||e===e.builder||r.write(a(e,"</"+e.name+">")),"function"==typeof e._stream_ready&&e._stream_ready(),e._stream_ready=!0}):void 0},t.prototype.ondata=function(e,t){var r,n=this;return null!=(r=e._stream)?r.write(function(){return n.write(t)}):void 0},t.prototype.ontext=function(e,t){var r,n=this;return null!=(r=e._stream)?r.write(function(){return n.write(a(e,t))}):void 0},t.prototype.onraw=function(e,t){var r,n=this;return null!=(r=e._stream)?r.write(function(){return n.write(t)}):void 0},t.prototype.onattr=function(e){return e.isempty&&e._stream_ready===!0?console.warn("attributes of "+e.toString()+" don't change anymore"):void 0},t.prototype.onend=function(){return null!=this.closed||0===this.opened_tags?this.close():(this.builder.closed="pending",this.closed=this.close)},t}(s),l=function(e,t){return new o(e,t),e},l.Adapter=o,t.exports=l,"browser"===process.title&&function(){return null!=this.dynamictemplate?this.dynamictemplate.streamify=l:this.dynamictemplate={streamify:l}}.call(window)}.call(this)}),e.define("stream",function(){}),e.define("/node_modules/ordered-emitter/package.json",function(e,t){t.exports={name:"ordered-emitter",version:"0.1.1",description:"emit events in order",main:"index.js",directories:{lib:".",example:"example",test:"test"},devDependencies:{tap:"~0.4.3"},scripts:{test:"tap test"},repository:{type:"git",url:"http://github.com/substack/node-ordered-emitter.git"},keywords:["ordered","buffer","event","emitter"],author:{name:"James Halliday",email:"mail@substack.net",url:"http://substack.net"},license:"MIT/X11",engine:{node:">=0.4"}}}),e.define("/node_modules/ordered-emitter/index.js",function(e,t){function r(e){n.call(this),e||(e={}),this._eventQueue={},this._next={},this.options=e}var n=e("events").EventEmitter,i=e("util").inherits;t.exports=r,i(r,n),r.prototype.reset=function(e){void 0===e?this._next={}:this._next[e]=0},r.prototype.clear=function(e){void 0===e?this._eventQueue={}:this._eventQueue[e]={}},r.prototype.emit=function(e,t){var r=function(e){n.prototype.emit.apply(this,e)}.bind(this,arguments),i=this._eventQueue,s=this._next,o=this.options.span?"*":e;if("object"==typeof t&&null!==t&&"number"==typeof t.order)if(s[o]||(s[o]=0),t.order===s[o])for(s[o]++,r();i[o]&&i[o][s[o]];)i[o][s[o]](),delete i[o][s[o]],s[o]++;else i[o]||(i[o]={}),i[o][t.order]=r;else r()}}),e.define("events",function(e,t,r){process.EventEmitter||(process.EventEmitter=function(){});var n=r.EventEmitter=process.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.toString.call(e)},s=10;n.prototype.setMaxListeners=function(e){this._events||(this._events={}),this._events.maxListeners=e},n.prototype.emit=function(e){if("error"===e&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var t=this._events[e];if(!t)return!1;if("function"==typeof t){switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:var r=Array.prototype.slice.call(arguments,1);t.apply(this,r)}return!0}if(i(t)){for(var r=Array.prototype.slice.call(arguments,1),n=t.slice(),s=0,o=n.length;o>s;s++)n[s].apply(this,r);return!0}return!1},n.prototype.addListener=function(e,t){if("function"!=typeof t)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",e,t),this._events[e])if(i(this._events[e])){if(!this._events[e].warned){var r;r=void 0!==this._events.maxListeners?this._events.maxListeners:s,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}this._events[e].push(t)}else this._events[e]=[this._events[e],t];else this._events[e]=t;return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){var r=this;return r.on(e,function n(){r.removeListener(e,n),t.apply(this,arguments)}),this},n.prototype.removeListener=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[e])return this;var r=this._events[e];if(i(r)){var n=r.indexOf(t);if(0>n)return this;r.splice(n,1),0==r.length&&delete this._events[e]}else this._events[e]===t&&delete this._events[e];return this},n.prototype.removeAllListeners=function(e){return e&&this._events&&this._events[e]&&(this._events[e]=null),this},n.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),i(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}}),e.define("util",function(){}),e.define("/util.js",function(e,t){!function(){var e,r,n,i;n=function(e){var t,r;return t=e.level,r=e.pretty,r===!0&&(r=" "),new Array(t+1).join(r)},r=function(e,t){var r,n;return r=e.level,n=e.pretty,n?"\n"===(null!=t?t[(null!=t?t.length:void 0)-1]:void 0)?t:""+t+"\n":t},i=function(e,t){return(null!=e?e.pretty:void 0)?""+n(e)+r(e,t):t},e=function(e){var t,r,n;return null==e&&(e={}),r=function(){var r;r=[];for(t in e)n=e[t],null!=n?("number"!=typeof n&&"boolean"!=typeof n&&(n='"'+n+'"'),r.push(""+t+"="+n)):r.push(""+t);return r}(),r.length&&r.unshift(""),r.join(" ")},t.exports={indent:n,breakline:r,prettify:i,attrStr:e}}.call(this)}),e("./dt-stream")}.call(this);