this.classed = function(name, value) { if(arguments.length < 2) { if(latte_lib.isString(name)) { var node = this.node(), n = (name = Utils.split_classes(name)).length, i = -1; if(value = node.classList) { while(++i < n) { if(!value.contains(name[i])) { return false; } } }else{ value = Utils.getAttr("class").call(node, this.getData()); while(++i < n) { if(!Utils.classedRe(name[i]).test(value)) { return false; } } } return true; } for(value in name) { Utils.classed(value, name[value]).call(this.node(), this.getData()); } return this; } Utils.classed(name, value).call(this.node()); return this; }
this.createServers = function(config) { if(latte_lib.isString(config)) { config = JSON.parse(fs.readFileSync(config, "utf8")); } setLogDir(config.logDir); if(config.servers) { for(var i in config.servers) { servers[i] = self.createServer(config.servers[i]); } } }
this.attr = function(name, value) { if(arguments.length < 2) { if(latte_lib.isString(name)) { return Utils.getAttr.call(this.node(), name); } for(value in name) { Utils.attr(value, name[value]).call(this.node(), this.getData()); } return this; } Utils.attr(name, value).call(this.node(), this.getData()); return this; }
function RPC(config) { if(latte_lib.isString(config)) { config = { path: config } }; this.config = latte_lib.merger(defaultConfig, config); this.methods = {}; this.watcher = null; this.id = 0; Load.call(this, config); //this.start(); };
function Rpc(config) { if(latte_lib.isString(config)) { config = { loadPath: config } } this.clean(); superClass.call(this, config); this.config = latte_verify.verify(this.config, verifyConfig); };
var getErrorString = function(err) { if(err.stack) { return err.stack.toString(); }else if(latte_lib.isString(err)) { return err.toString(); }else{ var errorString; try { errorString = JSON.stringify(err); }catch(e){ var Util = require("util"); errorString = Util.inspect(err); } return errorString; } }
this._send = function(data) { var res = this.res; if(data == null){ res.end(); }else if(latte_lib.isString(data)) { res.end(data); }else if(data.pipe) { data.pipe(res); }else if(data.constructor == Buffer) { res.end(data.toString()); }else if(data.stack) { res.end(data.stack); }else{ res.end(JSON.stringify(data)); } }
this.doWrite = function(data) { var isString = latte_lib.isString(data); var contentType = isString ? "text/plain; charset=UTF-8" : "application/octet-stream"; var contentLength = "" + (isString? Buffer.byteLength(data): data.length); var headers = { "Content-Type": contentType, "Content-Length": contentLength }; var ua = this.req.headers["user-agent"]; if(ua && (~ua.indexOf(";MSIE") || ~ua.indexOf("Trident/"))) { headers["X-XSS-Protection"] = "0"; } this.res.writeHead(200, this.headers(this.req, headers)); this.res.end(data); }
this.once = function(type, listener, capture) { var n = arguments.length; if(n < 3) { if(!latte_lib.isString(type)) { if(n < 2) listener = false; var self = this; for(var capture in type) { Utils.on(capture, onceFunc(capture, type[capture], listener, self), listener); } return this; } if(n < 2) { return false; } capture = false; } Utils.on(type, onceFunc(type, listener ,capture, this), capture).call(this.node(), this.getData()); return this; }
this.on = function(type, listener, capture) { var n = arguments.length; if(n < 3) { if(!latte_lib.isString(type)) { if(n < 2) listener = false; for(capture in type) { Utils.on(capture, type[capture], listener); } return this; } if(n < 2) { return (n = this.node()["__on" + type]) && n.map(function(o) { return o._; }); } capture = false; } Utils.on( type, listener, capture).call(this.node(), this.getData()); return this; }
this.style = function(name, value, priority) { var n = arguments.length; if(n < 3) { if(!latte_lib.isString(name)) { if( n < 2) value = ""; for(priority in name) { Utils.style(priority, name[priority], value).call(this.node(), this.getData()); } return this; } if(n < 2) { var node = this.node(); return Utils.window(node).getComputedStyle(node, null).getPropertyValue(name); } priority = ""; } Utils.style(name, value, priority).call(this.node(), this.getData()); return this; }
this.create = function(cssString, dom) { var css = new Css(dom); if(latte_lib.isString(cssString)) { var cssPrototypes = cssString.split(";"); cssPrototypes.forEach(function(cssPrototype) { var kv = cssPrototype.split(":"); if(kv.length == 2) { var key = kv[0]; var value = kv[1]; var openTag = value.indexOf("{{") ; if(openTag != -1) { var closeTag = value.indexOf("}}"); var o = value.substring(openTag+2, closeTag); css.bind(o, key, value); } } }); } return css; }
this.create = function(dom) { if(latte_lib.isString(dom)) { dom = Utils.select(dom, document); } return new View(dom); }