1 //<script type="text/javscript">
4 GLib = imports.gi.GLib;
6 imports['Object.js'].load(Object);
9 JSDOC = imports['JSDOC.js'].JSDOC;
10 console = imports['console.js'].console;
11 xnew = imports['xnew.js'].xnew;
12 Link = imports['JSDOC/Template/Link.js'].Link;
17 Template = function(templateFile) {
20 this.template = Gio.simple_read(templateFile);
24 this.templateFile = templateFile;
25 this.templateName = GLib.path_get_basename(templateFile);
30 xnew.load(Template , 'JSDOC/Template');
33 Object.extend(Template.prototype , {
38 console.log("Parsing template? " + this.templateName);
40 this.template = this.template.replace(/\{#[\s\S]+?#\}/gi, "");
41 this.code = "var output=``"+this.template;
43 this.code = this.code.replace(
44 /<for +each="(.+?)" +in="(.+?)" *>/gi,
45 function (match, eachName, inName) {
46 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+=``";
49 this.code = this.code.replace(/<if test="(.+?)">/g, "``;\rif ($1) { \routput+=``");
50 this.code = this.code.replace(/<else\s*\/>/g, "``;} \relse\r{ \routput+=``");
52 this.code = this.code.replace(/<\/(if|for)>/g, "``;\r};\routput+=``");
54 //File.write("/tmp/jstookit_eval_"+this.templateName+".4.js", this.code);
56 this.code = this.code.replace(
57 /\{\+\s*([\s\S]+?)\s*\+\}/gi,
58 function (match, code) {
59 code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
60 code = code.replace(/(\r?\n)/g, " ");
61 return "``+ \r("+code+") +\r``";
64 //File.write("/tmp/jstookit_eval_"+this.templateName+".6.js", this.code);
66 this.code = this.code.replace(
67 /\{!\s*([\s\S]+?)\s*!\}/gi,
68 function (match, code) {
69 code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
70 code = code.replace(/(\n)/g, " "); // remove quotes..
71 return "``; "+code+";\routput+=``";
74 //File.write("/tmp/jstookit_eval_"+this.templateName+".7.js", this.code);
75 this.code = this.code+"``;";
79 this.code = this.code.replace(/(\r?\n)/g, "\\n");
80 this.code = this.code.replace(/"/g, "\\\"");
82 this.code = this.code.replace(/``/g, "\"");
83 this.code = this.code.replace(/\\r/g, "\n");
84 //File.write("/tmp/jstookit_eval_"+this.templateName+".9.js", this.code);
85 this.code = this.code.replace(/\r/g, "\n\n");
94 keys : function(obj) {
96 if (obj && obj.constructor.toString().indexOf("Array") > -1) {
97 for (var i = 0; i < obj.length; i++) {
109 values : function(obj) {
111 if (obj.constructor.toString().indexOf("Array") > -1) {
112 for (var i = 0; i < obj.length; i++) {
126 process : function(data) {
128 //console.log("processing template");
129 var keys = this.keys;
130 var values = this.values;
132 var makeSortby = this.makeSortby;
133 var makeSignature = this.makeSignature;
134 var summarize = this.summarize ;
135 var makeFuncSkel = this.makeFuncSkel;
136 var resolveLinks = this.resolveLinks;
137 var makeImage = this.makeImage;
138 // usefull for cross refing..
139 Template.data = data;
146 Gio.simple_write('/tmp/template.js', this.code);
147 Seed.print('in /tmp/template.js');
153 //File.write("/tmp/jstookit_eval.js", this.code);
155 //eval('include "/tmp/jstookit_eval.js";');
156 //includeJs("/tmp/jstookit_eval.js");
158 // console.log("done eval of template");
164 isdefined : function (typ) {
165 return typ != 'undefined';
169 summarize : function(desc) {
170 if (typeof desc != "undefined")
171 return desc.match(/([\w\W]+?\.)[^a-z0-9]/i)? RegExp.$1 : desc;
174 /** make a symbol sorter by some attribute */
175 makeSortby : function(attribute) {
176 return function(a, b) {
177 if (a[attribute] != undefined && b[attribute] != undefined) {
178 a = a[attribute]; //.toLowerCase();
179 b = b[attribute];//.toLowerCase();
180 if (a < b) return -1;
186 makeImage : function(alias) {
187 /// http://library.gnome.org/devel/gtk/stable/notebook.png
188 var ns = alias.split('.').shift();
189 var cls = alias.split('.').pop().toLowerCase();
193 return '<img class="class-picture" src="http://library.gnome.org/devel/gtk/stable/' + cls + '.png">';
200 makeSignature : function(params) {
201 if (!params) return "()";
202 var signature = "(" +
205 return $.name.indexOf(".") == -1; // don't show config params in signature
209 $.defaultValue = typeof($.defaultValue) == 'undefined' ? false : $.defaultValue;
212 ($.isOptional ? "[" : "") +
214 (new Link().toSymbol(
215 (typeof($.type) == 'object' ) ? 'Function' : $.type
218 "<B><i>" +$.name + "</i></B>" +
219 ($.defaultValue ? "=" +item.defaultValue : "") +
220 ($.isOptional ? "]" : "");
230 makeFuncSkel : function(params) {
231 if (!params) return "function ()\n{\n\n}";
232 return "function (" +
235 return $.name.indexOf(".") == -1; // don't show config params in signature
237 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ")
243 /** Find symbol {@link ...} strings in text and turn into html links */
244 resolveLinks : function (str, from) {
245 if (!str || typeof(str) == 'undefined') {
249 // gtk specific. now..
250 // @ -> bold.. - they are arguments..
252 str = str.replace(/@([a-z_]+)/gi,
253 function(match, symbolName) {
254 return '<b>' + symbolName + '</b>';
258 str = str.replace(/%([a-z_]+)/gi,
259 function(match, symbolName) {
260 return '<b>' + symbolName + '</b>';
264 str = str.replace(/#([a-z_]+)/gi,
265 function(match, symbolName) {
266 return '<b>' + symbolName + '</b>';
267 // this should do a lookup!!!!
268 /// it could use data in the signature to find out..
269 //return new Link().toSymbol(Template.data.ns + '.' + symbolName);
273 str = str.replace(/\n/gi, '<br/>');
276 str = str.replace(/\{@link ([^} ]+) ?\}/gi,
277 function(match, symbolName) {
278 return new Link().toSymbol(symbolName);
283 str = str.replace(/\{([a-z\.\/]+)\}/gi,
284 function(match, symbolName) {
285 //println("got match " + symbolName);
286 bits = symbolName.split('/');
288 for(var i = 0; i < bits.length; i++) {
290 mret += (mret.length ? ' | ' : '') + new Link().toSymbol(bits[i]);
293 return mret; //new Link().toSymbol(symbolName);
297 // look for aaaa.\S+ ??? this might work???
299 str = str.replace(/\([a-z]+\.\S+)/gi,
300 function(match, symbolName) {
301 return new Link().toSymbol(symbolName);