1 //<script type="text/javscript">
2 JSDOC = imports['JSDOC.js'].JSDOC;
3 Roo = imports['Roo.js'].Roo;
4 console = imports['console.js'].console;
5 xnew = imports['xnew.js'].xnew;
8 GLib = imports.gi.GLib;
11 Link = imports['JSDOC/Template/Link.js'].Link;
13 Template = function(templateFile) {
16 this.template = Gio.simple_read(templateFile);
20 this.templateFile = templateFile;
21 this.templateName = GLib.path_get_basename(templateFile);
26 xnew.load(Template , 'JSDOC/Template');
29 Roo.apply(Template.prototype , {
34 console.log("Parsing template? " + this.templateName);
36 this.template = this.template.replace(/\{#[\s\S]+?#\}/gi, "");
37 this.code = "var output=``"+this.template;
39 this.code = this.code.replace(
40 /<for +each="(.+?)" +in="(.+?)" *>/gi,
41 function (match, eachName, inName) {
42 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+=``";
45 this.code = this.code.replace(/<if test="(.+?)">/g, "``;\rif ($1) { \routput+=``");
46 this.code = this.code.replace(/<else\s*\/>/g, "``;} \relse\r{ \routput+=``");
48 this.code = this.code.replace(/<\/(if|for)>/g, "``;\r};\routput+=``");
50 //File.write("/tmp/jstookit_eval_"+this.templateName+".4.js", this.code);
52 this.code = this.code.replace(
53 /\{\+\s*([\s\S]+?)\s*\+\}/gi,
54 function (match, code) {
55 code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
56 code = code.replace(/(\r?\n)/g, " ");
57 return "``+ \r("+code+") +\r``";
60 //File.write("/tmp/jstookit_eval_"+this.templateName+".6.js", this.code);
62 this.code = this.code.replace(
63 /\{!\s*([\s\S]+?)\s*!\}/gi,
64 function (match, code) {
65 code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
66 code = code.replace(/(\n)/g, " "); // remove quotes..
67 return "``; "+code+";\routput+=``";
70 //File.write("/tmp/jstookit_eval_"+this.templateName+".7.js", this.code);
71 this.code = this.code+"``;";
75 this.code = this.code.replace(/(\r?\n)/g, "\\n");
76 this.code = this.code.replace(/"/g, "\\\"");
78 this.code = this.code.replace(/``/g, "\"");
79 this.code = this.code.replace(/\\r/g, "\n");
80 //File.write("/tmp/jstookit_eval_"+this.templateName+".9.js", this.code);
81 this.code = this.code.replace(/\r/g, "\n\n");
90 keys : function(obj) {
92 if (obj && obj.constructor.toString().indexOf("Array") > -1) {
93 for (var i = 0; i < obj.length; i++) {
105 values : function(obj) {
107 if (obj.constructor.toString().indexOf("Array") > -1) {
108 for (var i = 0; i < obj.length; i++) {
122 process : function(data) {
124 //console.log("processing template");
125 var keys = this.keys;
126 var values = this.values;
128 var makeSortby = this.makeSortby;
129 var makeSignature = this.makeSignature;
130 var summarize = this.summarize ;
131 var makeFuncSkel = this.makeFuncSkel;
132 var resolveLinks = this.resolveLinks;
133 var makeImage = this.makeImage;
134 // usefull for cross refing..
135 Template.data = data;
142 Gio.simple_write('/tmp/template.js', this.code);
143 Seed.print('in /tmp/template.js');
149 //File.write("/tmp/jstookit_eval.js", this.code);
151 //eval('include "/tmp/jstookit_eval.js";');
152 //includeJs("/tmp/jstookit_eval.js");
154 // console.log("done eval of template");
160 isdefined : function (typ) {
161 return typ != 'undefined';
165 summarize : function(desc) {
166 if (typeof desc != "undefined")
167 return desc.match(/([\w\W]+?\.)[^a-z0-9]/i)? RegExp.$1 : desc;
170 /** make a symbol sorter by some attribute */
171 makeSortby : function(attribute) {
172 return function(a, b) {
173 if (a[attribute] != undefined && b[attribute] != undefined) {
174 a = a[attribute]; //.toLowerCase();
175 b = b[attribute];//.toLowerCase();
176 if (a < b) return -1;
182 makeImage : function(alias) {
183 /// http://library.gnome.org/devel/gtk/stable/notebook.png
184 var ns = alias.split('.').shift();
185 var cls = alias.split('.').pop().toLowerCase();
189 return '<img class="class-picture" src="http://library.gnome.org/devel/gtk/stable/' + cls + '.png">';
196 makeSignature : function(params) {
197 if (!params) return "()";
198 var signature = "(" +
201 return $.name.indexOf(".") == -1; // don't show config params in signature
205 $.defaultValue = typeof($.defaultValue) == 'undefined' ? false : $.defaultValue;
208 ($.isOptional ? "[" : "") +
210 (new Link().toSymbol(
211 (typeof($.type) == 'object' ) ? 'Function' : $.type
214 "<B><i>" +$.name + "</i></B>" +
215 ($.defaultValue ? "=" +item.defaultValue : "") +
216 ($.isOptional ? "]" : "");
226 makeFuncSkel : function(params) {
227 if (!params) return "function ()\n{\n\n}";
228 return "function (" +
231 return $.name.indexOf(".") == -1; // don't show config params in signature
233 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ")
239 /** Find symbol {@link ...} strings in text and turn into html links */
240 resolveLinks : function (str, from) {
241 if (!str || typeof(str) == 'undefined') {
245 // gtk specific. now..
246 // @ -> bold.. - they are arguments..
248 str = str.replace(/@([a-z_]+)/gi,
249 function(match, symbolName) {
250 return '<b>' + symbolName + '</b>';
254 str = str.replace(/%([a-z_]+)/gi,
255 function(match, symbolName) {
256 return '<b>' + symbolName + '</b>';
260 str = str.replace(/#([a-z_]+)/gi,
261 function(match, symbolName) {
262 return '<b>' + symbolName + '</b>';
263 // this should do a lookup!!!!
264 /// it could use data in the signature to find out..
265 //return new Link().toSymbol(Template.data.ns + '.' + symbolName);
269 str = str.replace(/\n/gi, '<br/>');
272 str = str.replace(/\{@link ([^} ]+) ?\}/gi,
273 function(match, symbolName) {
274 return new Link().toSymbol(symbolName);
279 str = str.replace(/\{([a-z\.\/]+)\}/gi,
280 function(match, symbolName) {
281 //println("got match " + symbolName);
282 bits = symbolName.split('/');
284 for(var i = 0; i < bits.length; i++) {
286 mret += (mret.length ? ' | ' : '') + new Link().toSymbol(bits[i]);
289 return mret; //new Link().toSymbol(symbolName);
293 // look for aaaa.\S+ ??? this might work???
295 str = str.replace(/\([a-z]+\.\S+)/gi,
296 function(match, symbolName) {
297 return new Link().toSymbol(symbolName);