Built files accidentally included.
[jquery.git] / build / docs.js
1 load("js/json.js");
2 load("js/xml.js");
3 load("js/writeFile.js");
4
5 var types = {
6         jQuery: "A jQuery object.",
7         Object: "A simple Javascript object. For example, it could be a String or a Number.",
8         String: "A string of characters.",
9         Number: "A numeric valid.",
10         Element: "The Javascript object representation of a DOM Element.",
11         Hash: "A Javascript object that contains key/value pairs in the form of properties and values.",
12         "Array<Element>": "An Array of DOM Elements.",
13         "Array<String>": "An Array of strings.",
14         Function: "A reference to a Javascript function."
15 };
16
17 var f = readFile(arguments[0]);
18
19 var c = [], bm, m;
20 var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g;
21 var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m;
22
23 while ( bm = blockMatch.exec(f) ) {
24         block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!";
25         var ret = { params: [], examples: [] };
26
27         while ( m = paramMatch.exec( block ) ) {
28                 block = block.replace( paramMatch, "" );
29
30                 var n = m[1];
31                 var v = m[2]
32                         .replace(/\s*$/g,"")
33                         .replace(/^\s*/g,"")
34                         .replace(/&/g, "&")
35                         .replace(/</g, "&lt;")
36                         .replace(/>/g, "&gt;")
37                         .replace(/\n/g, "<br/>")
38                         /*.replace(/(\s\s+)/g, function(a){
39                                 var ret = "";
40                                 for ( var i = 0; i < a.length; i++ )
41                                         ret += "&nbsp;";
42                                 return ret;
43                         })*/ || 1;
44
45                 if ( n == 'param' || n == 'any' ) {
46                         var args = v.split(/\s+/);
47                         v = args.slice( 2, args.length );
48                         v = { type: args[0], name: args[1], desc: v.join(' ') };
49                         if ( n == 'any' ) v.any = 1;
50                         n = "params";
51                 } else if ( n == 'example' ) {
52                         v = { code: v };
53                         n = "examples";
54                 }
55
56                 if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) {
57                         ret.examples[ ret.examples.length - 1 ][ n ] = v;
58                 } else {
59                         if ( ret[ n ] ) {
60                                 if ( ret[ n ].constructor == Array ) {
61                                         ret[ n ].push( v );
62                                 } else {
63                                         ret[ n ] = [ ret[ n ], v ];
64                                 }
65                         } else {
66                                 ret[ n ] = v;
67                         }
68                 }
69         }
70   
71         ret.desc = block.replace(/\s*!!!$/,"")
72                         .replace(/</g, "&lt;")
73                         .replace(/>/g, "&gt;");
74                         //.replace(/\n\n/g, "<br/><br/>")
75                         //.replace(/\n/g, " ");
76
77         var m = /^((.|\n)*?(\.|$))/.exec( ret.desc );
78         if ( m ) ret['short'] = m[1];
79
80         if ( ret.name ) c.push( ret );
81 }
82
83 var json = Object.toJSON( c );
84
85 writeFile( arguments[1] + "/data/jquery-docs-json.js", json );
86 writeFile( arguments[1] + "/data/jquery-docs-jsonp.js", "docsLoaded(" + json + ")" );
87
88 Object.toXML.force = { desc: 1, code: 1, before: 1, result: 1 };
89
90 var xml = Object.toXML( { method: c }, "docs" );
91
92 writeFile( arguments[1] + "/data/jquery-docs-xml.xml", 
93         "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + xml );
94
95 writeFile( arguments[1] + "/index.xml",
96         "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
97         "<?xml-stylesheet type='text/xsl' href='style/docs.xsl'?>\n" + xml
98 );