roojs-doc.js
[roojs1] / roojs-doc-debug.js
1 /*
2  * - LGPL
3  *
4  *  Documentation - designed to generate HTML+Docbook!?!
5  */
6 Roo.doc = Roo.doc || {};
7
8 /**
9  * @class Roo.doc.Entry
10  * @extends Roo.bootstrap.Component
11  * Entry Element class - describes a method etc...
12  * @cfg name {String} name of method
13  * @cfg purpose {String} short description of method.
14  * 
15  * @constructor
16  * Create a new E
17  * @param {Object} config The config object
18  */
19
20
21
22 Roo.doc.Entry  = function(config){
23     Roo.doc.Entry.superclass.constructor.call(this, config);
24     //this.el = Roo.get(document.body);
25     var body = Roo.get(document.body);
26     body.attr({
27         leftmargin : 0,
28         marginwidth : 0,
29         topmargin : 0,
30         marginheight : 0,
31         offset : 0
32     });
33     
34      
35     // call onRender once... and block next call...?
36     this.onRender(body);
37     this.el = body;
38     //this.onRender = function() { };
39
40 };
41
42 Roo.doc.Entry._calls = 0;
43
44 Roo.extend(Roo.doc.Entry, Roo.bootstrap.Component,  {
45     
46     
47     name : '',
48     purpose : '',
49     
50     getAutoCreate : function(){
51         
52         var cfg ={
53             cls : 'refentry',
54             cn : [
55                 {
56                     tag: 'h1',
57                     cls: 'refname',
58                     html : this.name
59                 },
60                 {
61                     cls: 'refnamediv',
62                     html : this.purpose
63                 }
64             ]
65         };
66         
67         
68          
69         
70         return cfg;
71     },
72     
73     addxtype :   function (tree, cntr)
74     {
75         return this.addxtypeChild(tree,cntr);
76     },
77     
78     onRender : function(ct, position)
79     {
80         
81         Roo.doc.Entry._calls++;
82         if (Roo.doc.Entry._calls > 1 || !ct) {
83             return;
84         }
85         
86     // call onRender once... and block next call...?
87     
88         Roo.bootstrap.Component.prototype.onRender.call(this, ct, position);
89     }
90    
91 });
92
93  
94
95  /*
96  * - LGPL
97  *
98  */
99
100 /**
101  * @class Roo.doc.Example
102  * @extends Roo.bootstrap.Component
103  * Example Element class
104  * @cfg {String} title short title describing example
105  * @cfg {String} lang (php|txt|sql) section type.
106  * @cfg {String} code  example code
107  * @cfg {String} output The expected output from the code
108  *
109  * 
110  * @constructor
111  * Create a new Synopsis
112  * @param {Object} config The config object
113  */
114
115 Roo.doc.Example = function(config){
116     Roo.doc.Example.superclass.constructor.call(this, config);
117 };
118
119 Roo.extend(Roo.doc.Example, Roo.bootstrap.Component,  {
120     
121     title : '',
122     lang:   'php',
123     code : '',
124     output : '',
125     
126     getAutoCreate : function(){
127         
128         // no colour highlighting in here....
129         
130         var code = hljs ? hljs.highlight(this.code, this.lang) : String.format('{0}',this.code).replace(/\n/g, '<br/>');
131         
132         
133         var cfg ={
134             cls : 'panel panel-info',
135             cn : [
136                 {
137                     cls : 'panel-heading',
138                     html : this.title
139                 },
140                 {
141                     cls : 'panel-body',
142                     cn : [
143                         {
144                             tag: 'pre',
145                             cls : 'lang-' + this.lang,
146                             html :  code
147                         }
148                     ]
149                 }
150             ]
151         };
152         
153         if (this.output) {
154             cfg.cn.push(
155
156                 {
157                     cls : 'panel-footer',
158                     cn : {
159                         tag: 'code',
160                         html :  String.format('{0}',this.output).replace(/\n/g, '<br/>')
161                     }
162                 }
163             
164                 
165             );
166         }
167         
168         
169         
170         return cfg;
171     }
172   
173     
174     
175    
176 });
177
178  
179
180  /*
181  * - LGPL
182  *
183  */
184
185 /**
186  * @class Roo.doc.Para
187  * @extends Roo.bootstrap.Component
188  * Param Element class
189  * @cfg {String} html
190  * 
191  * @constructor
192  * Create a new Paragraph
193  * @param {Object} config The config object
194  */
195
196 Roo.doc.Para = function(config){
197     Roo.doc.Para.superclass.constructor.call(this, config);
198 };
199
200 Roo.extend(Roo.doc.Para, Roo.bootstrap.Component,  {
201     
202     html : '',
203     getAutoCreate : function(){
204         
205         //?? this is the synopsis type....
206         
207         // this is not very fancy...
208         
209         var cfg ={
210             tag: 'p',
211             cls: 'para',
212             html : this.html
213         };
214          
215         if (this.parent().is_list) {
216             return {
217                 tag: 'li',
218                 cls : listitme,
219                 cn : [ cfg ]
220             };
221             
222         }
223         
224         return cfg;
225     }
226      
227     
228     
229     
230     
231    
232 });
233
234  
235
236  /*
237  * - LGPL
238  *
239  */
240
241 /**
242  * @class Roo.doc.Param
243  * @extends Roo.bootstrap.Component
244  * Param Element class
245  * @cfg {bool} is_optional is the argument optional
246  * @cfg {String} type  argument type
247  * @cfg {String} name name of the parameter
248  * @cfg {String} desc  short description
249  * @cfg {String} defaultvalue default value
250  * 
251  * @constructor
252  * Create a new Param
253  * @param {Object} config The config object
254  */
255
256 Roo.doc.Param = function(config){
257     Roo.doc.Param.superclass.constructor.call(this, config);
258 };
259
260 Roo.extend(Roo.doc.Param, Roo.bootstrap.Component,  {
261     
262     is_optional : false,
263     type : '',
264     name: '',
265     defaultvalue:   '',
266     desc: '',
267      
268     getAutoCreate : function(){
269         
270         //?? this is the synopsis type....
271         
272         
273         if (this.parent().stype == 'parameter') {
274             
275             return {
276                 tag : 'li',
277                 cn : [
278                     {
279                         tag : 'p',
280                         cls: 'para',
281                         cn : [
282                             {
283                                 tag: 'code',
284                                 html : this.type + ' ' + this.name
285                             },
286                             this.desc
287                         ]
288                     }
289                 ]
290             };
291             
292         }
293          if (this.parent().stype == 'return') {
294             return {
295                     tag : 'p',
296                     cls: 'para',
297                     cn : [
298                         {
299                             tag: 'code',
300                             html : this.type
301                         },
302                         this.desc
303                     ]
304                 };
305                 
306          }
307        
308         
309         
310         // this is not very fancy...
311         
312         var cfg ={
313             tag: 'span',
314             cn : [
315                 this.is_optional ? '[' : '',
316                 this.type,
317                 ' ',
318                 {
319                     tag : 'b',
320                     html : this.name
321                 },
322                 this.defaultvalue == '' ? '' : ' = ',
323                 this.defaultvalue,
324                 this.is_optional ? ']' : '',
325                 ',' // not really.. but let's do it anyway...
326             ]
327         };
328          
329         
330         
331         
332         return cfg;
333     },
334     getAutoCreateParamSection : function()
335     {
336         return {
337                tag : 'li',
338                cn : [
339                    {
340                        tag : 'p',
341                        cls: 'para',
342                        cn : [
343                            {
344                                tag: 'code',
345                                html : this.type + ' ' + this.name
346                            },
347                            this.desc
348                        ]
349                    }
350                ]
351            };
352         
353         
354     }
355     
356      
357     
358     
359     
360     
361    
362 });
363
364  
365
366  /*
367  * - LGPL
368  *
369  */
370
371 /**
372  * @class Roo.doc.Section
373  * @extends Roo.bootstrap.Component
374  * SectionElement class
375  * @cfg {String} stype (desc|parameter|return|note|example) section type.
376  * 
377  * @constructor
378  * Create a new Synopsis
379  * @param {Object} config The config object
380  */
381
382 Roo.doc.Section = function(config){
383     Roo.doc.Section.superclass.constructor.call(this, config);
384 };
385
386 Roo.extend(Roo.doc.Section, Roo.bootstrap.Component,  {
387     
388     
389     stype:   '',
390      
391     getAutoCreate : function(){
392         
393         
394         
395         
396         var cfg ={
397             
398             cls : 'refsection',
399             // id... ?
400             cn : [
401                 {
402                     tag: 'h3',
403                     cls : 'title',
404                     html : Roo.doc.Section.map[this.stype] 
405                 }
406             ]
407         };
408         if (this.stype == 'parameter') {
409             
410             // db package uses variable list here... - it results in dd/dl but the layout is messed up..
411             
412             var ul = {
413                 tag: 'ul',
414                 cls: 'itemizedlist roo-params',
415                 cn : []
416             };
417             // might not have any..
418             var params = this.parent().items[0].items;
419             for (var i =0; i < params.length;i++) {
420                 ul.cn.push( Roo.factory(params[i]).getAutoCreateParamSection() )
421             }
422             
423             
424             cfg.cn.push(ul);
425         }
426         
427         
428         return cfg;
429     },
430     getChildContainer : function(build_call)
431     {
432          
433         if (this.stype == 'parameter') {
434             return this.el.select('.roo-params',true).first();
435         }
436         return this.el;
437     }
438     
439     
440    
441 });
442
443  
444 Roo.doc.Section.map = {
445     'desc' : 'Description',
446     'parameter' : 'Parameters',
447     'return' : 'Return Value',
448     'note' : 'Notes',
449     'example' : 'Examples'
450 }
451 /*
452  * - LGPL
453  *
454  */
455
456 /**
457  * @class Roo.doc.Synopsis
458  * @extends Roo.bootstrap.Component
459  * Synopsis Element class
460  * @cfg {String} returntype return value
461  * @cfg {String} name title really..
462  * @cfg {String} stype (function|constant)
463  * @cfg {String} memberof class name
464  * @cfg {bool} is_static is a static member
465  * 
466  * @constructor
467  * Create a new Synopsis
468  * @param {Object} config The config object
469  */
470
471 Roo.doc.Synopsis = function(config){
472     Roo.doc.Synopsis.superclass.constructor.call(this, config);
473 };
474
475 Roo.extend(Roo.doc.Synopsis, Roo.bootstrap.Component,  {
476     
477     memberof : '',
478     is_static : false,
479     returntype : '',
480     name: '',
481     stype:   'function',
482      
483     getAutoCreate : function(){
484         
485         var syn = this.items[0]; // hopefully...
486         Roo.log(this.items);
487         
488          
489         var cfg ={
490             tag: 'h5',
491             cls : 'refsynopsisdiv',
492             cn : [
493                 {
494                     cls: 'funcsynopsis',
495                     cn: [
496                         {
497                             tag: 'p',
498                             cn: {
499                                 tag:'code',
500                                 cls : 'funcprototype',
501                                 cn: [
502                                     this.returntype + ' ',
503                                     {
504                                         tag: 'strong',
505                                         cls : this.stype,
506                                         html : this.name
507                                     },
508                                     '(',
509                                     {
510                                         tag: 'span',
511                                         cls : 'roo-params'
512                                     },
513                                     ')'
514                                 ]
515                                 
516                             }
517                         }
518                     ]
519                 }
520                 
521             ]
522         };
523         
524         
525         
526         return cfg;
527     },
528     getChildContainer : function(build_call)
529     {
530          
531         
532         return this.el.select('.roo-params',true).first();
533     }
534     
535     
536     
537     
538    
539 });
540
541  
542
543