Roo/doc/Example.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 (phpcode|programlisting) 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 cfg ={
131             cls : 'panel panel-info',
132             cn : [
133                 {
134                     cls : 'panel-heading',
135                     html : this.title
136                 },
137                 {
138                     cls : 'panel-body',
139                     cn : [
140                         {
141                             tag: 'pre',
142                             cls : this.lang,
143                             html :  String.format('{0}',this.code).replace(/\n/g, '<br/>')
144                         }
145                     ]
146                 }
147             ]
148         };
149         
150         if (this.output) {
151             cfg.cn.push(
152
153                 {
154                     cls : 'panel-footer',
155                     cn : {
156                         tag: 'code',
157                         html :  String.format('{0}',this.output).replace(/\n/g, '<br/>')
158                     }
159                 }
160             
161                 
162             );
163         }
164         
165         
166         
167         return cfg;
168     }
169   
170     
171     
172    
173 });
174
175  
176
177  /*
178  * - LGPL
179  *
180  */
181
182 /**
183  * @class Roo.doc.Para
184  * @extends Roo.bootstrap.Component
185  * Param Element class
186  * @cfg {String} html
187  * 
188  * @constructor
189  * Create a new Paragraph
190  * @param {Object} config The config object
191  */
192
193 Roo.doc.Para = function(config){
194     Roo.doc.Para.superclass.constructor.call(this, config);
195 };
196
197 Roo.extend(Roo.doc.Para, Roo.bootstrap.Component,  {
198     
199     html : '',
200     getAutoCreate : function(){
201         
202         //?? this is the synopsis type....
203         
204         // this is not very fancy...
205         
206         var cfg ={
207             tag: 'p',
208             cls: 'para',
209             html : this.html
210         };
211          
212         if (this.parent().is_list) {
213             return {
214                 tag: 'li',
215                 cls : listitme,
216                 cn : [ cfg ]
217             };
218             
219         }
220         
221         return cfg;
222     }
223      
224     
225     
226     
227     
228    
229 });
230
231  
232
233  /*
234  * - LGPL
235  *
236  */
237
238 /**
239  * @class Roo.doc.Param
240  * @extends Roo.bootstrap.Component
241  * Param Element class
242  * @cfg {bool} is_optional is the argument optional
243  * @cfg {String} type  argument type
244  * @cfg {String} name name of the parameter
245  * @cfg {String} desc  short description
246  * @cfg {String} defaultvalue default value
247  * 
248  * @constructor
249  * Create a new Param
250  * @param {Object} config The config object
251  */
252
253 Roo.doc.Param = function(config){
254     Roo.doc.Param.superclass.constructor.call(this, config);
255 };
256
257 Roo.extend(Roo.doc.Param, Roo.bootstrap.Component,  {
258     
259     is_optional : false,
260     type : '',
261     name: '',
262     defaultvalue:   '',
263     desc: '',
264      
265     getAutoCreate : function(){
266         
267         //?? this is the synopsis type....
268         
269         
270         if (this.parent().stype == 'parameter') {
271             
272             return {
273                 tag : 'li',
274                 cn : [
275                     {
276                         tag : 'p',
277                         cls: 'para',
278                         cn : [
279                             {
280                                 tag: 'code',
281                                 html : this.type + ' ' + this.name
282                             },
283                             this.desc
284                         ]
285                     }
286                 ]
287             };
288             
289         }
290          if (this.parent().stype == 'return') {
291             return {
292                     tag : 'p',
293                     cls: 'para',
294                     cn : [
295                         {
296                             tag: 'code',
297                             html : this.type
298                         },
299                         this.desc
300                     ]
301                 };
302                 
303          }
304        
305         
306         
307         // this is not very fancy...
308         
309         var cfg ={
310             tag: 'span',
311             cn : [
312                 this.is_optional ? '[' : '',
313                 this.type,
314                 ' ',
315                 {
316                     tag : 'b',
317                     html : this.name
318                 },
319                 this.defaultvalue == '' ? '' : ' = ',
320                 this.defaultvalue,
321                 this.is_optional ? ']' : '',
322                 ',' // not really.. but let's do it anyway...
323             ]
324         };
325          
326         
327         
328         
329         return cfg;
330     },
331     getAutoCreateParamSection : function()
332     {
333         return {
334                tag : 'li',
335                cn : [
336                    {
337                        tag : 'p',
338                        cls: 'para',
339                        cn : [
340                            {
341                                tag: 'code',
342                                html : this.type + ' ' + this.name
343                            },
344                            this.desc
345                        ]
346                    }
347                ]
348            };
349         
350         
351     }
352     
353      
354     
355     
356     
357     
358    
359 });
360
361  
362
363  /*
364  * - LGPL
365  *
366  */
367
368 /**
369  * @class Roo.doc.Section
370  * @extends Roo.bootstrap.Component
371  * SectionElement class
372  * @cfg {String} stype (desc|parameter|return|note|example) section type.
373  * 
374  * @constructor
375  * Create a new Synopsis
376  * @param {Object} config The config object
377  */
378
379 Roo.doc.Section = function(config){
380     Roo.doc.Section.superclass.constructor.call(this, config);
381 };
382
383 Roo.extend(Roo.doc.Section, Roo.bootstrap.Component,  {
384     
385     
386     stype:   '',
387      
388     getAutoCreate : function(){
389         
390         
391         
392         
393         var cfg ={
394             
395             cls : 'refsection',
396             // id... ?
397             cn : [
398                 {
399                     tag: 'h3',
400                     cls : 'title',
401                     html : Roo.doc.Section.map[this.stype] 
402                 }
403             ]
404         };
405         if (this.stype == 'parameter') {
406             
407             // db package uses variable list here... - it results in dd/dl but the layout is messed up..
408             
409             var ul = {
410                 tag: 'ul',
411                 cls: 'itemizedlist roo-params',
412                 cn : []
413             };
414             // might not have any..
415             var params = this.parent().items[0].items;
416             for (var i =0; i < params.length;i++) {
417                 ul.cn.push( Roo.factory(params[i]).getAutoCreateParamSection() )
418             }
419             
420             
421             cfg.cn.push(ul);
422         }
423         
424         
425         return cfg;
426     },
427     getChildContainer : function(build_call)
428     {
429          
430         if (this.stype == 'parameter') {
431             return this.el.select('.roo-params',true).first();
432         }
433         return this.el;
434     }
435     
436     
437    
438 });
439
440  
441 Roo.doc.Section.map = {
442     'desc' : 'Description',
443     'parameter' : 'Parameters',
444     'return' : 'Return Value',
445     'note' : 'Notes',
446     'example' : 'Examples'
447 }
448 /*
449  * - LGPL
450  *
451  */
452
453 /**
454  * @class Roo.doc.Synopsis
455  * @extends Roo.bootstrap.Component
456  * Synopsis Element class
457  * @cfg {String} returntype return value
458  * @cfg {String} name title really..
459  * @cfg {String} stype (function|constant)
460  * @cfg {String} memberof class name
461  * @cfg {bool} is_static is a static member
462  * 
463  * @constructor
464  * Create a new Synopsis
465  * @param {Object} config The config object
466  */
467
468 Roo.doc.Synopsis = function(config){
469     Roo.doc.Synopsis.superclass.constructor.call(this, config);
470 };
471
472 Roo.extend(Roo.doc.Synopsis, Roo.bootstrap.Component,  {
473     
474     memberof : '',
475     is_static : false,
476     returntype : '',
477     name: '',
478     stype:   'function',
479      
480     getAutoCreate : function(){
481         
482         var syn = this.items[0]; // hopefully...
483         Roo.log(this.items);
484         
485          
486         var cfg ={
487             tag: 'h5',
488             cls : 'refsynopsisdiv',
489             cn : [
490                 {
491                     cls: 'funcsynopsis',
492                     cn: [
493                         {
494                             tag: 'p',
495                             cn: {
496                                 tag:'code',
497                                 cls : 'funcprototype',
498                                 cn: [
499                                     this.returntype + ' ',
500                                     {
501                                         tag: 'strong',
502                                         cls : this.stype,
503                                         html : this.name
504                                     },
505                                     '(',
506                                     {
507                                         tag: 'span',
508                                         cls : 'roo-params'
509                                     },
510                                     ')'
511                                 ]
512                                 
513                             }
514                         }
515                     ]
516                 }
517                 
518             ]
519         };
520         
521         
522         
523         return cfg;
524     },
525     getChildContainer : function(build_call)
526     {
527          
528         
529         return this.el.select('.roo-params',true).first();
530     }
531     
532     
533     
534     
535    
536 });
537
538  
539
540