diff options
author | John Resig <jeresig@gmail.com> | 2006-08-14 01:46:05 +0000 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2006-08-14 01:46:05 +0000 |
commit | 7448c61ee2199f6f7002e33e533cebc42b000c89 (patch) | |
tree | 71e0d08a590cf2ce29cc49057b7f4a76037f62c2 /build/js | |
parent | 61aab47bcf4c35d021a88d95b7a17643d1342596 (diff) | |
download | jquery-7448c61ee2199f6f7002e33e533cebc42b000c89.tar.gz jquery-7448c61ee2199f6f7002e33e533cebc42b000c89.zip |
Massive overhauls to the test suite - it is now generated dynamically, along with the documentation.
Diffstat (limited to 'build/js')
-rw-r--r-- | build/js/parse.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/build/js/parse.js b/build/js/parse.js new file mode 100644 index 000000000..5b60b0a5b --- /dev/null +++ b/build/js/parse.js @@ -0,0 +1,69 @@ +function parse( f ) { + var c = [], bm, m; + var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g; + var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m; + + while ( bm = blockMatch.exec(f) ) { + block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!"; + var ret = { params: [], examples: [], tests: [] }; + + while ( m = paramMatch.exec( block ) ) { + block = block.replace( paramMatch, "" ); + + var n = m[1]; + var v = m[2] + .replace(/\s*$/g,"") + .replace(/^\s*/g,"") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + //.replace(/\n/g, "<br/>") + /*.replace(/(\s\s+)/g, function(a){ + var ret = ""; + for ( var i = 0; i < a.length; i++ ) + ret += " "; + return ret; + })*/ || 1; + + if ( n == 'param' || n == 'any' ) { + var args = v.split(/\s+/); + v = args.slice( 2, args.length ); + v = { type: args[0], name: args[1], desc: v.join(' ') }; + if ( n == 'any' ) v.any = 1; + n = "params"; + } else if ( n == 'example' ) { + v = { code: v }; + n = "examples"; + } else if ( n == 'test' ) { + n = "tests"; + } + + if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) { + ret.examples[ ret.examples.length - 1 ][ n ] = v; + } else { + if ( ret[ n ] ) { + if ( ret[ n ].constructor == Array ) { + ret[ n ].push( v ); + } else { + ret[ n ] = [ ret[ n ], v ]; + } + } else { + ret[ n ] = v; + } + } + } + + ret.desc = block.replace(/\s*!!!$/,"") + .replace(/</g, "<") + .replace(/>/g, ">"); + //.replace(/\n\n/g, "<br/><br/>") + //.replace(/\n/g, " "); + + var m = /^((.|\n)*?(\.|$))/.exec( ret.desc ); + if ( m ) ret['short'] = m[1]; + + if ( ret.name ) c.push( ret ); + } + + return c; +} |