From ccabf2823b528c09455432cafdb504c6a0216a18 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 22 Aug 2006 05:00:07 +0000 Subject: [PATCH] Updated the documentation parser to work with categories. Additionally, I updated the copyright notice in the jQuery header and removed some extraneous whitespace from jQuery Lite. --- build/build/lite.js | 2 +- build/docs/docs.js | 31 ++++++++++++++++++++----------- build/js/parse.js | 28 ++++++++++++++++++++++++++++ build/js/xml.js | 2 +- src/jquery/jquery.js | 3 ++- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/build/build/lite.js b/build/build/lite.js index 650009a..5fb923b 100644 --- a/build/build/lite.js +++ b/build/build/lite.js @@ -1,6 +1,6 @@ load("build/js/writeFile.js"); var blockMatch = /\s*\/\*\*\s*((.|\n)*?)\s*\*\/\n*/g; -var f = readFile(arguments[0]).replace( blockMatch, "\n" ); +var f = readFile(arguments[0]).replace( blockMatch, "\n" ).replace( /\n\n+/g, "\n\n" ); writeFile( arguments[1], f ); diff --git a/build/docs/docs.js b/build/docs/docs.js index 6e77b94..6574f6b 100644 --- a/build/docs/docs.js +++ b/build/docs/docs.js @@ -1,19 +1,28 @@ load("build/js/json.js", "build/js/xml.js", "build/js/writeFile.js", "build/js/parse.js"); +var dir = arguments[1]; + var c = parse( readFile(arguments[0]) ); -var json = Object.toJSON( c ); +output( c, "docs" ); -writeFile( arguments[1] + "/data/jquery-docs-json.js", json ); -writeFile( arguments[1] + "/data/jquery-docs-jsonp.js", "docsLoaded(" + json + ")" ); +c = categorize( c ); +output( c, "cat" ); -Object.toXML.force = { desc: 1, code: 1, before: 1, result: 1 }; +function output( c, n ) { + var json = Object.toJSON( c ); -var xml = Object.toXML( { method: c }, "docs" ); + writeFile( dir + "/data/jquery-" + n + "-json.js", json ); + writeFile( dir + "/data/jquery-" + n + "-jsonp.js", "docsLoaded(" + json + ")" ); -writeFile( arguments[1] + "/data/jquery-docs-xml.xml", - "\n" + xml ); + Object.toXML.force = { desc: 1, code: 1, before: 1, result: 1 }; + + var xml = Object.toXML( n == "docs" ? { method: c } : c, "docs" ); + + writeFile( dir + "/data/jquery-" + n + "-xml.xml", + "\n" + xml ); -writeFile( arguments[1] + "/index.xml", - "\n" + - "\n" + xml -); + writeFile( dir + "/" + ( n == "docs" ? "index" : n ) + ".xml", + "\n" + + "\n" + xml + ); +} diff --git a/build/js/parse.js b/build/js/parse.js index 5b60b0a..c9454d1 100644 --- a/build/js/parse.js +++ b/build/js/parse.js @@ -67,3 +67,31 @@ function parse( f ) { return c; } + +function categorize( json ) { + var obj = { methods: [] }; + + for ( var i = 0; i < json.length; i++ ) { + if ( !json[i].cat ) json[i].cat = ""; + + var cat = json[i].cat.split("/"); + + var pos = obj; + for ( var j = 0; j < cat.length; j++ ) { + var c = cat[j]; + + // Create current category + if ( !pos[c] ) pos[c] = { methods: [] }; + + // If we're at the end, add the method + if ( j == cat.length - 1 ) + pos[c].methods.push( json[i] ); + + // Otherwise, traverse deeper + else + pos = pos[c]; + } + } + + return obj; +} diff --git a/build/js/xml.js b/build/js/xml.js index cc94eb7..b2b09c6 100644 --- a/build/js/xml.js +++ b/build/js/xml.js @@ -9,7 +9,7 @@ Object.toXML = function( obj, tag ) { var p = "", child = ""; for ( var i in obj ) - if ( obj[i].constructor == Array || /