Roo/doc/Param.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) 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) {
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 }
479 /*
480  * - LGPL
481  *
482  */
483
484 /**
485  * @class Roo.doc.Synopsis
486  * @extends Roo.bootstrap.Component
487  * Synopsis Element class
488  * @cfg {String} returntype return value
489  * @cfg {String} returndesc description of return value. (used in the return section if set..)
490  * @cfg {String} name title really..
491  * @cfg {String} stype (function|constant)
492  * @cfg {String} memberof class name
493  * @cfg {bool} is_static is a static member
494  * 
495  * @constructor
496  * Create a new Synopsis
497  * @param {Object} config The config object
498  */
499
500 Roo.doc.Synopsis = function(config){
501     Roo.doc.Synopsis.superclass.constructor.call(this, config);
502 };
503
504 Roo.extend(Roo.doc.Synopsis, Roo.bootstrap.Component,  {
505     
506     memberof : '',
507     is_static : false,
508     returntype : '',
509     returndesc : '',
510     name: '',
511     stype:   'function',
512      
513     getAutoCreate : function(){
514         
515         var syn = this.items[0]; // hopefully...
516         
517         
518         
519         var nmp = (this.is_static ? '' : '$') +
520             this.memberof +
521             (this.is_static ? '::' : '->');
522             
523          
524         // this should probably do the params....?? then we need to disable the rendering..
525         
526          
527         var cfg ={
528             tag: 'h5',
529             cls : 'refsynopsisdiv',
530             cn : [
531                 {
532                     cls: 'funcsynopsis',
533                     cn: [
534                         {
535                             tag: 'p',
536                             cn: {
537                                 tag:'code',
538                                 cls : 'funcprototype',
539                                 cn: [
540                                     this.returntype + ' ' + nmp,
541                                     {
542                                         tag: 'strong',
543                                         cls : this.stype,
544                                         html : this.name
545                                     },
546                                     '(',
547                                     {
548                                         tag: 'span',
549                                         cls : 'roo-params'
550                                     },
551                                     ')'
552                                 ]
553                                 
554                             }
555                         }
556                     ]
557                 }
558                 
559             ]
560         };
561         
562         
563         
564         return cfg;
565     },
566     getChildContainer : function(build_call)
567     {
568          
569         
570         return this.el.select('.roo-params',true).first();
571     }
572     
573     
574     
575     
576    
577 });
578
579  
580
581  /*
582  * - LGPL
583  *
584  */
585
586 /**
587  * @class Roo.doc.NavCategory
588  * @extends Roo.bootstrap.Component
589  * Navigation Category class
590  * @cfg {string} title
591  * @cfg {string} name
592  *
593  * Represent's an category on the left menu.
594  * - phpdoc @category elements map the pages to the categories
595  *   this should be on the left side of the menu, when the
596  *   contents are loaded, then it can expand this out, and add links
597  *   for each of the methods.
598  *
599  * 
600  * 
601  * @constructor
602  * Create a new Navigation Category
603  * @param {Object} config The config object
604  */
605
606 Roo.doc.NavCategory = function(config){
607     Roo.doc.Para.superclass.constructor.call(this, config);
608     Roo.doc.NavCategory.registry[this.name] = this;
609 };
610 Roo.doc.NavCategory.registry = {};
611 Roo.extend(Roo.doc.NavCategory, Roo.bootstrap.Component,  {
612     
613     title : '',
614     name : '',
615     getAutoCreate : function(){
616         
617         //?? this is the synopsis type....
618         
619         // this is not very fancy...
620         
621         var cfg ={
622             
623             cn : [
624                 
625                 {
626                     tag : 'a',
627                     cls: 'roo-nav-category',
628                     href : '#' + this.name,
629                     html : this.title
630                 },
631                 {
632                     cls : 'container roo-child-ctr'
633                 }
634             ]
635         };
636
637         return cfg;
638     },
639     getChildContainer : function()
640     {
641         return this.el.select('.roo-child-ctr',true).first();
642     }
643     
644     
645    
646 });
647
648  
649
650