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     /*
26     var body = Roo.get(document.body);
27     body.attr({
28         leftmargin : 0,
29         marginwidth : 0,
30         topmargin : 0,
31         marginheight : 0,
32         offset : 0
33     });
34     
35      
36     // call onRender once... and block next call...?
37     this.onRender(body);
38     this.el = body;
39     //this.onRender = function() { };
40     */
41
42 };
43
44 //Roo.doc.Entry._calls = 0;
45
46 Roo.extend(Roo.doc.Entry, Roo.bootstrap.Component,  {
47     
48     
49     name : '',
50     purpose : '',
51     
52     getAutoCreate : function(){
53         
54         var cfg ={
55             cls : 'refentry',
56             cn : [
57                 {
58                     tag: 'h1',
59                     cls: 'refname',
60                     html : this.name
61                 },
62                 {
63                     cls: 'refnamediv',
64                     html : this.purpose
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  /*
97  * - LGPL
98  *
99  */
100
101 /**
102  * @class Roo.doc.Example
103  * @extends Roo.bootstrap.Component
104  * Example Element class
105  * @cfg {String} title short title describing example
106  * @cfg {String} lang (php|txt|sql) section type.
107  * @cfg {String} code  example code
108  * @cfg {String} output The expected output from the code
109  *
110  * 
111  * @constructor
112  * Create a new Synopsis
113  * @param {Object} config The config object
114  */
115
116 Roo.doc.Example = function(config){
117     Roo.doc.Example.superclass.constructor.call(this, config);
118 };
119
120 Roo.extend(Roo.doc.Example, Roo.bootstrap.Component,  {
121     
122     title : '',
123     lang:   'php',
124     code : '',
125     output : '',
126     outputlang : 'txt',
127     
128     getAutoCreate : function(){
129         
130         // no colour highlighting in here....
131         
132         var code = hljs ? hljs.highlight(this.lang,this.code).value :
133                 String.format('{0}',this.code).replace(/\n/g, '<br/>');
134         
135         
136         var cfg ={
137             cls : 'panel panel-info',
138             cn : [
139                 {
140                     cls : 'panel-heading',
141                     html : this.title
142                 },
143                 {
144                     cls : 'panel-body',
145                     cn : [
146                         {
147                             tag: 'pre',
148                             cls : 'lang-' + this.lang,
149                             html :  code
150                         }
151                     ]
152                 }
153             ]
154         };
155         
156         if (this.output) {
157             
158             var out = hljs ? hljs.highlight(this.outputlang,this.output).value :
159                     String.format('{0}',this.output).replace(/\n/g, '<br/>');
160             cfg.cn.push(
161
162                 {
163                     cls : 'panel-footer',
164                     cn : {
165                         tag: 'pre',
166                         html : out 
167                     }
168                 }
169             
170                 
171             );      
172         }
173         
174         
175         
176         return cfg;
177     }
178   
179     
180     
181    
182 });
183
184  
185
186  /*
187  * - LGPL
188  *
189  */
190
191 /**
192  * @class Roo.doc.Para
193  * @extends Roo.bootstrap.Component
194  * Param Element class
195  * @cfg {String} html
196  * 
197  * @constructor
198  * Create a new Paragraph
199  * @param {Object} config The config object
200  */
201
202 Roo.doc.Para = function(config){
203     Roo.doc.Para.superclass.constructor.call(this, config);
204 };
205
206 Roo.extend(Roo.doc.Para, Roo.bootstrap.Component,  {
207     
208     html : '',
209     getAutoCreate : function(){
210         
211         //?? this is the synopsis type....
212         
213         // this is not very fancy...
214         
215         var cfg ={
216             tag: 'p',
217             cls: 'para',
218             html : this.html
219         };
220          
221         if (this.parent().is_list) {
222             return {
223                 tag: 'li',
224                 cls : listitme,
225                 cn : [ cfg ]
226             };
227             
228         }
229         
230         return cfg;
231     }
232      
233     
234     
235     
236     
237    
238 });
239
240  
241
242  /*
243  * - LGPL
244  *
245  */
246
247 /**
248  * @class Roo.doc.Param
249  * @extends Roo.bootstrap.Component
250  * Param Element class
251  * @cfg {bool} is_optional is the argument optional
252  * @cfg {String} type  argument type
253  * @cfg {String} name name of the parameter
254  * @cfg {String} desc  short description
255  * @cfg {String} defaultvalue default value
256  * 
257  * @constructor
258  * Create a new Param
259  * @param {Object} config The config object
260  */
261
262 Roo.doc.Param = function(config){
263     Roo.doc.Param.superclass.constructor.call(this, config);
264 };
265
266 Roo.extend(Roo.doc.Param, Roo.bootstrap.Component,  {
267     
268     is_optional : false,
269     type : '',
270     name: '',
271     defaultvalue:   '',
272     desc: '',
273      
274     getAutoCreate : function(){
275         
276         //?? this is the synopsis type....
277         
278         
279         if (this.parent().stype == 'parameter') {
280             
281             return {
282                 tag : 'li',
283                 cn : [
284                     {
285                         tag : 'p',
286                         cls: 'para',
287                         cn : [
288                             {
289                                 tag: 'code',
290                                 html : this.type + ' ' + this.name
291                             },
292                             this.desc
293                         ]
294                     }
295                 ]
296             };
297             
298         }
299          if (this.parent().stype == 'return') {
300             return {
301                     tag : 'p',
302                     cls: 'para',
303                     cn : [
304                         {
305                             tag: 'code',
306                             html : this.type
307                         },
308                         this.desc
309                     ]
310                 };
311                 
312          }
313        
314         
315         
316         // this is not very fancy...
317         
318         var cfg ={
319             tag: 'span',
320             cn : [
321                 this.is_optional ? '[' : '',
322                 this.type,
323                 ' ',
324                 {
325                     tag : 'b',
326                     html : this.name
327                 },
328                 this.defaultvalue == '' ? '' : ' = ',
329                 this.defaultvalue,
330                 this.is_optional ? ']' : '',
331                 ',' // not really.. but let's do it anyway...
332             ]
333         };
334          
335         
336         
337         
338         return cfg;
339     },
340     getAutoCreateParamSection : function()
341     {
342         return {
343                tag : 'li',
344                cn : [
345                    {
346                        tag : 'p',
347                        cls: 'para',
348                        cn : [
349                            {
350                                tag: 'code',
351                                html : this.type + ' ' + this.name
352                            },
353                            this.desc
354                        ]
355                    }
356                ]
357            };
358         
359         
360     }
361     
362      
363     
364     
365     
366     
367    
368 });
369
370  
371
372  /*
373  * - LGPL
374  *
375  */
376
377 /**
378  * @class Roo.doc.Section
379  * @extends Roo.bootstrap.Component
380  * SectionElement class
381  * @cfg {String} stype (desc|parameter|return|note|example) section type.
382  * 
383  * @constructor
384  * Create a new Synopsis
385  * @param {Object} config The config object
386  */
387
388 Roo.doc.Section = function(config){
389     Roo.doc.Section.superclass.constructor.call(this, config);
390 };
391
392 Roo.extend(Roo.doc.Section, Roo.bootstrap.Component,  {
393     
394     
395     stype:   '',
396      
397     getAutoCreate : function(){
398         
399         
400         var syn = Roo.factory(this.parent().items[0]);
401         
402         var cfg ={
403             
404             cls : 'refsection',
405             // id... ?
406             cn : [
407                 {
408                     tag: 'h3',
409                     cls : 'title',
410                     html : Roo.doc.Section.map[this.stype] 
411                 }
412             ]
413         };
414         if (this.stype == 'parameter') {
415             
416             // db package uses variable list here... - it results in dd/dl but the layout is messed up..
417             
418             var ul = {
419                 tag: 'ul',
420                 cls: 'itemizedlist roo-params',
421                 cn : []
422             };
423             // might not have any..
424             var params = syn.items;
425             for (var i =0; i < params.length;i++) {
426                 ul.cn.push( Roo.factory(params[i]).getAutoCreateParamSection() )
427             }
428             
429             
430             cfg.cn.push(ul);
431         }
432         if (this.stype == 'return' && syn.returndesc.length) {
433             
434             cfg.cn.push({
435                 tag: 'p',
436                 cls : 'para',
437                 cn : [
438                 
439                     {
440                         tag: 'code',
441                         cls: 'parameter',
442                         html : syn.returntype
443                     },
444                     syn.returndesc
445                 ]
446                 
447             });
448         }
449         
450         return cfg;
451     },
452     getChildContainer : function(build_call)
453     {
454          
455         if (this.stype == 'parameter') {
456             return this.el.select('.roo-params',true).first();
457         }
458        
459         return this.el;
460     }
461     
462     
463    
464 });
465
466  
467 Roo.doc.Section.map = {
468     'desc' : 'Description',
469     'parameter' : 'Parameters',
470     'return' : 'Return Value',
471     'note' : 'Notes',
472     'example' : 'Examples'
473 }
474 /*
475  * - LGPL
476  *
477  */
478
479 /**
480  * @class Roo.doc.Synopsis
481  * @extends Roo.bootstrap.Component
482  * Synopsis Element class
483  * @cfg {String} returntype return value
484  * @cfg {String} returndesc description of return value. (used in the return section if set..)
485  * @cfg {String} name title really..
486  * @cfg {String} stype (function|constant)
487  * @cfg {String} memberof class name
488  * @cfg {bool} is_static is a static member
489  * 
490  * @constructor
491  * Create a new Synopsis
492  * @param {Object} config The config object
493  */
494
495 Roo.doc.Synopsis = function(config){
496     Roo.doc.Synopsis.superclass.constructor.call(this, config);
497 };
498
499 Roo.extend(Roo.doc.Synopsis, Roo.bootstrap.Component,  {
500     
501     memberof : '',
502     is_static : false,
503     returntype : '',
504     returndesc : '',
505     name: '',
506     stype:   'function',
507      
508     getAutoCreate : function(){
509         
510         var syn = this.items[0]; // hopefully...
511         
512         
513         
514         var nmp = (this.is_static ? '' : '$') +
515             this.memberof +
516             (this.is_static ? '::' : '->');
517             
518          
519         // this should probably do the params....?? then we need to disable the rendering..
520         
521          
522         var cfg ={
523             tag: 'h5',
524             cls : 'refsynopsisdiv',
525             cn : [
526                 {
527                     cls: 'funcsynopsis',
528                     cn: [
529                         {
530                             tag: 'p',
531                             cn: {
532                                 tag:'code',
533                                 cls : 'funcprototype',
534                                 cn: [
535                                     this.returntype + ' ' + nmp,
536                                     {
537                                         tag: 'strong',
538                                         cls : this.stype,
539                                         html : this.name
540                                     },
541                                     '(',
542                                     {
543                                         tag: 'span',
544                                         cls : 'roo-params'
545                                     },
546                                     ')'
547                                 ]
548                                 
549                             }
550                         }
551                     ]
552                 }
553                 
554             ]
555         };
556         
557         
558         
559         return cfg;
560     },
561     getChildContainer : function(build_call)
562     {
563          
564         
565         return this.el.select('.roo-params',true).first();
566     }
567     
568     
569     
570     
571    
572 });
573
574  
575
576  /*
577  * - LGPL
578  *
579  */
580
581 /**
582  * @class Roo.doc.NavCategory
583  * @extends Roo.bootstrap.Component
584  * Navigation Category class
585  * @cfg {string} title
586  * @cfg {string} name
587  *
588  * Represent's an category on the left menu.
589  * - phpdoc @category elements map the pages to the categories
590  *   this should be on the left side of the menu, when the
591  *   contents are loaded, then it can expand this out, and add links
592  *   for each of the methods.
593  *
594  * 
595  * 
596  * @constructor
597  * Create a new Navigation Category
598  * @param {Object} config The config object
599  */
600
601 Roo.doc.NavCategory = function(config){
602     Roo.doc.Para.superclass.constructor.call(this, config);
603 };
604
605 Roo.extend(Roo.doc.NavCategory, Roo.bootstrap.Component,  {
606     
607     title : '',
608     name : '',
609     getAutoCreate : function(){
610         
611         //?? this is the synopsis type....
612         
613         // this is not very fancy...
614         
615         var cfg ={
616             
617             cn : [
618                 
619                 {
620                     tag : 'a',
621                     cls: 'roo-nav-category',
622                     href : '#' + this.name,
623                     html : this.title
624                 },
625                 {
626                     cls : 'container roo-child-ctr'
627                 }
628             ]
629         };
630
631         return cfg;
632     },
633     getChildContainer : function()
634     {
635         return this.el.select('roo-child-ctr',true).first();
636     }
637     
638     
639    
640 });
641
642  
643
644