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