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