Just added support for Accept headers in Ajax requests - defaults to the correct...
[jquery.git] / build / js / parse.js
1 function parse( f ) {
2         var c = [], bm, m;
3         var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g;
4         var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m;
5         
6         while ( bm = blockMatch.exec(f) ) {
7                 block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!";
8                 var ret = { params: [], examples: [], tests: [], options: [] };
9         
10                 while ( m = paramMatch.exec( block ) ) {
11                         block = block.replace( paramMatch, "" );
12
13                         var n = m[1];
14                         var v = m[2]
15                                 .replace(/\s*$/g,"")
16                                 .replace(/^\s*/g,"")
17                                 .replace(/&/g, "&")
18                                 .replace(/</g, "&lt;")
19                                 .replace(/>/g, "&gt;")
20                                 //.replace(/\n/g, "<br/>")
21                                 /*.replace(/(\s\s+)/g, function(a){
22                                         var ret = "";
23                                         for ( var i = 0; i < a.length; i++ )
24                                                 ret += "&nbsp;";
25                                         return ret;
26                                 })*/ || 1;
27         
28                         if ( n == 'param' || n == 'option' ) {
29                                 var args = v.split(/\s+/);
30                                 v = args.slice( 2, args.length );
31                                 v = { type: args[0], name: args[1], desc: v.join(' ') };
32                                 n = n + "s";
33                         } else if ( n == 'example' ) {
34                                 v = { code: v };
35                                 n = "examples";
36                         } else if ( n == 'test' ) {
37                                 n = "tests";
38                         }
39         
40                         if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) {
41                                 ret.examples[ ret.examples.length - 1 ][ n ] = v;
42                         } else {
43                                 if ( ret[ n ] ) {
44                                         if ( ret[ n ].constructor == Array ) {
45                                                 ret[ n ].push( v );
46                                         } else {
47                                                 ret[ n ] = [ ret[ n ], v ];
48                                         }
49                                 } else {
50                                         ret[ n ] = v;
51                                 }
52                         }
53                 }
54         
55                 ret.desc = block.replace(/\s*!!!$/,"")
56                                 .replace(/</g, "&lt;")
57                                 .replace(/>/g, "&gt;");
58                                 //.replace(/\n\n/g, "<br/><br/>")
59                                 //.replace(/\n/g, " ");
60         
61                 var m = /^((.|\n)*?(\.|$))/.exec( ret.desc );
62                 if ( m ) ret['short'] = m[1];
63         
64                 if ( ret.name ) c.push( ret );
65         }
66
67         return c;
68 }
69
70 function categorize( json ) {
71         var obj = { cat: [], method: [] };
72
73         for ( var i = 0; i < json.length; i++ ) {
74                 if ( !json[i].cat ) json[i].cat = "";
75
76                 var cat = json[i].cat.split("/");
77
78                 var pos = obj;
79                 for ( var j = 0; j < cat.length; j++ ) {
80                         var c = cat[j];
81                         var curCat = null;
82
83                         // Locate current category
84                         for ( var n = 0; n < pos.cat.length; n++ )
85                                 if ( pos.cat[n].value == c )
86                                         curCat = pos.cat[n];
87
88                         // Create current category
89                         if ( !curCat ) {
90                                 curCat = { value: c, cat: [], method: [] };
91                                 pos.cat.push( curCat )
92                         }
93
94                         // If we're at  the end, add the method
95                         if ( j == cat.length - 1 )
96                                 curCat.method.push( json[i] );
97
98                         // Otherwise, traverse deeper
99                         else
100                                 pos = curCat;
101                 }
102         }
103
104         return obj;
105 }