From bc0cf5be634c11458061a0364c12d08fda732671 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 28 Jun 2010 17:54:58 +0800 Subject: [PATCH] JSDOC/Template.js --- JSDOC/Template.js | 505 +++++++++++++++++++++++----------------------- 1 file changed, 251 insertions(+), 254 deletions(-) diff --git a/JSDOC/Template.js b/JSDOC/Template.js index f394b08..cec981a 100644 --- a/JSDOC/Template.js +++ b/JSDOC/Template.js @@ -32,286 +32,283 @@ Template = XObject.define( this.templateName = GLib.path_get_basename(templateFile); this.code = ""; this.parse(); - } - - - - -XObject.extend(Template.prototype , { + }, + Object, { - parse : function() { - - console.log("Parsing template? " + this.templateName); - - this.template = this.template.replace(/\{#[\s\S]+?#\}/gi, ""); - this.code = "var output=``"+this.template; + parse : function() { + + console.log("Parsing template? " + this.templateName); + + this.template = this.template.replace(/\{#[\s\S]+?#\}/gi, ""); + this.code = "var output=``"+this.template; - this.code = this.code.replace( - //gi, - function (match, eachName, inName) { - return "``;\rvar $"+eachName+"_keys = keys("+inName+");\rfor(var $"+eachName+"_i = 0; $"+eachName+"_i < $"+eachName+"_keys.length; $"+eachName+"_i++) {\rvar $"+eachName+"_last = ($"+eachName+"_i == $"+eachName+"_keys.length-1);\rvar $"+eachName+"_key = $"+eachName+"_keys[$"+eachName+"_i];\rvar "+eachName+" = "+inName+"[$"+eachName+"_key];\routput+=``"; - } - ); - this.code = this.code.replace(//g, "``;\rif ($1) { \routput+=``"); - this.code = this.code.replace(//g, "``;} \relse\r{ \routput+=``"); - - this.code = this.code.replace(/<\/(if|for)>/g, "``;\r};\routput+=``"); - - //File.write("/tmp/jstookit_eval_"+this.templateName+".4.js", this.code); - - this.code = this.code.replace( - /\{\+\s*([\s\S]+?)\s*\+\}/gi, - function (match, code) { - code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code - code = code.replace(/(\r?\n)/g, " "); - return "``+ \r("+code+") +\r``"; - } - ); - //File.write("/tmp/jstookit_eval_"+this.templateName+".6.js", this.code); - - this.code = this.code.replace( - /\{!\s*([\s\S]+?)\s*!\}/gi, - function (match, code) { - code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code - code = code.replace(/(\n)/g, " "); // remove quotes.. - return "``; "+code+";\routput+=``"; - } - ); - //File.write("/tmp/jstookit_eval_"+this.templateName+".7.js", this.code); - this.code = this.code+"``;"; + this.code = this.code.replace( + //gi, + function (match, eachName, inName) { + return "``;\rvar $"+eachName+"_keys = keys("+inName+");\rfor(var $"+eachName+"_i = 0; $"+eachName+"_i < $"+eachName+"_keys.length; $"+eachName+"_i++) {\rvar $"+eachName+"_last = ($"+eachName+"_i == $"+eachName+"_keys.length-1);\rvar $"+eachName+"_key = $"+eachName+"_keys[$"+eachName+"_i];\rvar "+eachName+" = "+inName+"[$"+eachName+"_key];\routput+=``"; + } + ); + this.code = this.code.replace(//g, "``;\rif ($1) { \routput+=``"); + this.code = this.code.replace(//g, "``;} \relse\r{ \routput+=``"); + + this.code = this.code.replace(/<\/(if|for)>/g, "``;\r};\routput+=``"); + + //File.write("/tmp/jstookit_eval_"+this.templateName+".4.js", this.code); + + this.code = this.code.replace( + /\{\+\s*([\s\S]+?)\s*\+\}/gi, + function (match, code) { + code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code + code = code.replace(/(\r?\n)/g, " "); + return "``+ \r("+code+") +\r``"; + } + ); + //File.write("/tmp/jstookit_eval_"+this.templateName+".6.js", this.code); + + this.code = this.code.replace( + /\{!\s*([\s\S]+?)\s*!\}/gi, + function (match, code) { + code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code + code = code.replace(/(\n)/g, " "); // remove quotes.. + return "``; "+code+";\routput+=``"; + } + ); + //File.write("/tmp/jstookit_eval_"+this.templateName+".7.js", this.code); + this.code = this.code+"``;"; - - - this.code = this.code.replace(/(\r?\n)/g, "\\n"); - this.code = this.code.replace(/"/g, "\\\""); - - this.code = this.code.replace(/``/g, "\""); - this.code = this.code.replace(/\\r/g, "\n"); - //File.write("/tmp/jstookit_eval_"+this.templateName+".9.js", this.code); - this.code = this.code.replace(/\r/g, "\n\n"); - + + + this.code = this.code.replace(/(\r?\n)/g, "\\n"); + this.code = this.code.replace(/"/g, "\\\""); + + this.code = this.code.replace(/``/g, "\""); + this.code = this.code.replace(/\\r/g, "\n"); + //File.write("/tmp/jstookit_eval_"+this.templateName+".9.js", this.code); + this.code = this.code.replace(/\r/g, "\n\n"); + - }, + }, - toCode : function() { - return this.code; - }, + toCode : function() { + return this.code; + }, - keys : function(obj) { - var keys = []; - if (obj && obj.constructor.toString().indexOf("Array") > -1) { - for (var i = 0; i < obj.length; i++) { - keys.push(i); + keys : function(obj) { + var keys = []; + if (obj && obj.constructor.toString().indexOf("Array") > -1) { + for (var i = 0; i < obj.length; i++) { + keys.push(i); + } } - } - else { - for (var i in obj) { - keys.push(i); + else { + for (var i in obj) { + keys.push(i); + } } - } - return keys; - }, + return keys; + }, - values : function(obj) { - var values = []; - if (obj.constructor.toString().indexOf("Array") > -1) { - for (var i = 0; i < obj.length; i++) { - values.push(obj[i]); + values : function(obj) { + var values = []; + if (obj.constructor.toString().indexOf("Array") > -1) { + for (var i = 0; i < obj.length; i++) { + values.push(obj[i]); + } } - } - else { - for (var i in obj) { - values.push(obj[i]); + else { + for (var i in obj) { + values.push(obj[i]); + } } - } - - - return values; - }, + + + return values; + }, - process : function(data) { - - //console.log("processing template"); - var keys = this.keys; - var values = this.values; - - var makeSortby = this.makeSortby; - var makeSignature = this.makeSignature; - var summarize = this.summarize ; - var makeFuncSkel = this.makeFuncSkel; - var resolveLinks = this.resolveLinks; - var makeImage = this.makeImage; - // usefull for cross refing.. - Template.data = data; - + process : function(data) { + + //console.log("processing template"); + var keys = this.keys; + var values = this.values; + + var makeSortby = this.makeSortby; + var makeSignature = this.makeSignature; + var summarize = this.summarize ; + var makeFuncSkel = this.makeFuncSkel; + var resolveLinks = this.resolveLinks; + var makeImage = this.makeImage; + // usefull for cross refing.. + Template.data = data; + + var Link = this.Link; + + try { + eval(this.code); + } catch (e) { + Gio.simple_write('/tmp/template.js', this.code); + Seed.print('in /tmp/template.js'); + throw e; + Seed.quit(); + } + + + //File.write("/tmp/jstookit_eval.js", this.code); + //try { + //eval('include "/tmp/jstookit_eval.js";'); + //includeJs("/tmp/jstookit_eval.js"); + //eval(this.code); + // console.log("done eval of template"); + + return output; + }, + + + isdefined : function (typ) { + return typ != 'undefined'; + }, - try { - eval(this.code); - } catch (e) { - Gio.simple_write('/tmp/template.js', this.code); - Seed.print('in /tmp/template.js'); - throw e; - Seed.quit(); + summarize : function(desc) { + if (typeof desc != "undefined") + return desc.match(/([\w\W]+?\.)[^a-z0-9]/i)? RegExp.$1 : desc; + }, + + /** make a symbol sorter by some attribute */ + makeSortby : function(attribute) { + return function(a, b) { + if (a[attribute] != undefined && b[attribute] != undefined) { + a = a[attribute]; //.toLowerCase(); + b = b[attribute];//.toLowerCase(); + if (a < b) return -1; + if (a > b) return 1; + return 0; + } } + }, + makeImage : function(alias) { + /// http://library.gnome.org/devel/gtk/stable/notebook.png + var ns = alias.split('.').shift(); + var cls = alias.split('.').pop().toLowerCase(); + if (ns != 'Gtk' ) { + return '';//ns; + } + return ''; + + + }, - //File.write("/tmp/jstookit_eval.js", this.code); - //try { - //eval('include "/tmp/jstookit_eval.js";'); - //includeJs("/tmp/jstookit_eval.js"); - //eval(this.code); - // console.log("done eval of template"); - - return output; - }, - - isdefined : function (typ) { - return typ != 'undefined'; - }, - - - summarize : function(desc) { - if (typeof desc != "undefined") - return desc.match(/([\w\W]+?\.)[^a-z0-9]/i)? RegExp.$1 : desc; - }, + makeSignature : function(params) { + if (!params) return "()"; + var _this = this; + var signature = "(" + + params.filter( + function($) { + return $.name.indexOf(".") == -1; // don't show config params in signature + } + ).map( + function($) { + $.defaultValue = typeof($.defaultValue) == 'undefined' ? false : $.defaultValue; + + return "" + + ($.isOptional ? "[" : "") + + (($.type) ? + (new _this.Link().toSymbol( + (typeof($.type) == 'object' ) ? 'Function' : $.type + )) + " " : "" + ) + + "" +$.name + "" + + ($.defaultValue ? "=" +item.defaultValue : "") + + ($.isOptional ? "]" : ""); + + + } + ).join(", ") + + + ")"; + return signature; + }, - /** make a symbol sorter by some attribute */ - makeSortby : function(attribute) { - return function(a, b) { - if (a[attribute] != undefined && b[attribute] != undefined) { - a = a[attribute]; //.toLowerCase(); - b = b[attribute];//.toLowerCase(); - if (a < b) return -1; - if (a > b) return 1; - return 0; - } - } - }, - makeImage : function(alias) { - /// http://library.gnome.org/devel/gtk/stable/notebook.png - var ns = alias.split('.').shift(); - var cls = alias.split('.').pop().toLowerCase(); - if (ns != 'Gtk' ) { - return '';//ns; - } - return ''; - - - }, - - + makeFuncSkel : function(params) { + if (!params) return "function ()\n{\n\n}"; + return "function (" + + params.filter( + function($) { + return $.name.indexOf(".") == -1; // don't show config params in signature + } + ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") + + + ")\n{\n\n}"; + + }, - makeSignature : function(params) { - if (!params) return "()"; - var signature = "(" + - params.filter( - function($) { - return $.name.indexOf(".") == -1; // don't show config params in signature + /** Find symbol {@link ...} strings in text and turn into html links */ + resolveLinks : function (str, from) { + if (!str || typeof(str) == 'undefined') { + return ''; + } + + // gtk specific. now.. + // @ -> bold.. - they are arguments.. + + str = str.replace(/@([a-z_]+)/gi, + function(match, symbolName) { + return '' + symbolName + ''; } - ).map( - function($) { - $.defaultValue = typeof($.defaultValue) == 'undefined' ? false : $.defaultValue; - - return "" + - ($.isOptional ? "[" : "") + - (($.type) ? - (new Link().toSymbol( - (typeof($.type) == 'object' ) ? 'Function' : $.type - )) + " " : "" - ) + - "" +$.name + "" + - ($.defaultValue ? "=" +item.defaultValue : "") + - ($.isOptional ? "]" : ""); + ); + // constants. + str = str.replace(/%([a-z_]+)/gi, + function(match, symbolName) { + return '' + symbolName + ''; + } + ); + + str = str.replace(/#([a-z_]+)/gi, + function(match, symbolName) { + return '' + symbolName + ''; + // this should do a lookup!!!! + /// it could use data in the signature to find out.. + //return new Link().toSymbol(Template.data.ns + '.' + symbolName); + } + ); + + str = str.replace(/\n/gi, '
'); + + /* + str = str.replace(/\{@link ([^} ]+) ?\}/gi, + function(match, symbolName) { + return new Link().toSymbol(symbolName); + } + ); + */ + /* + str = str.replace(/\{([a-z\.\/]+)\}/gi, + function(match, symbolName) { + //println("got match " + symbolName); + bits = symbolName.split('/'); + var mret = ''; + for(var i = 0; i < bits.length; i++) { + + mret += (mret.length ? ' | ' : '') + new Link().toSymbol(bits[i]); + } - + return mret; //new Link().toSymbol(symbolName); } - ).join(", ") - + - ")"; - return signature; - }, - - makeFuncSkel : function(params) { - if (!params) return "function ()\n{\n\n}"; - return "function (" + - params.filter( - function($) { - return $.name.indexOf(".") == -1; // don't show config params in signature + ); + */ + // look for aaaa.\S+ ??? this might work??? + /* + str = str.replace(/\([a-z]+\.\S+)/gi, + function(match, symbolName) { + return new Link().toSymbol(symbolName); } - ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") - + - ")\n{\n\n}"; - - }, - - /** Find symbol {@link ...} strings in text and turn into html links */ - resolveLinks : function (str, from) { - if (!str || typeof(str) == 'undefined') { - return ''; + ); + */ + + return str; } - // gtk specific. now.. - // @ -> bold.. - they are arguments.. - - str = str.replace(/@([a-z_]+)/gi, - function(match, symbolName) { - return '' + symbolName + ''; - } - ); - // constants. - str = str.replace(/%([a-z_]+)/gi, - function(match, symbolName) { - return '' + symbolName + ''; - } - ); - - str = str.replace(/#([a-z_]+)/gi, - function(match, symbolName) { - return '' + symbolName + ''; - // this should do a lookup!!!! - /// it could use data in the signature to find out.. - //return new Link().toSymbol(Template.data.ns + '.' + symbolName); - } - ); - - str = str.replace(/\n/gi, '
'); - /* - str = str.replace(/\{@link ([^} ]+) ?\}/gi, - function(match, symbolName) { - return new Link().toSymbol(symbolName); - } - ); - */ - /* - str = str.replace(/\{([a-z\.\/]+)\}/gi, - function(match, symbolName) { - //println("got match " + symbolName); - bits = symbolName.split('/'); - var mret = ''; - for(var i = 0; i < bits.length; i++) { - - mret += (mret.length ? ' | ' : '') + new Link().toSymbol(bits[i]); - } - - return mret; //new Link().toSymbol(symbolName); - } - ); - */ - // look for aaaa.\S+ ??? this might work??? - /* - str = str.replace(/\([a-z]+\.\S+)/gi, - function(match, symbolName) { - return new Link().toSymbol(symbolName); - } - ); - */ - - return str; - } - - }); \ No newline at end of file -- 2.39.2