Skip to content

Commit

Permalink
More fixes to handle properties better when generating documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Jan 23, 2012
1 parent e8b9ac3 commit 1d4c51f
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 97 deletions.
76 changes: 3 additions & 73 deletions dev/tools/build-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var buildTestHash = function(objects) {
}

// Push the object on the list
objectsByClassAndMethod[tagObject['_class']][tagObject['_function']].push(block);
objectsByClassAndMethod[tagObject['_class']][tagObject['_function']].push(block);

// Format the block code
var codeLines = block.code.split(/\n/);
Expand Down Expand Up @@ -106,7 +106,8 @@ var apiClasses = [

// All test files
var testClasses = [
{path:"./test/admin_test.js"}
{path:"./test/admin_test.js"},
{path:"./test/objectid_test.js"}
]

// Read all the templates
Expand Down Expand Up @@ -173,89 +174,18 @@ var renderAllTemplates = function(outputDirectory, templates, dataObjects, testO
{entries:classMetaData, examples:classExamplesData, isClass:isClass,
isFunction:isFunction, isProperty:isProperty, format:format});

// console.dir("------------------------------------------------------------------- -1")
// console.dir(templates)
// console.dir("------------------------------------------------------------------- 0")
// for(var j = 0; j < classMetaData.length; j++) {
// console.dir(classMetaData[j]);
// }
// console.dir(classMetaData)
console.dir("------------------------------------------------------------------- -1")
console.dir("------------------------------------------------------------------- -1")
console.dir("------------------------------------------------------------------- -1")
console.log(classContent)

// Write out the content to disk
fs.writeFileSync(format("%s/%s.rst", outputDirectory, className), classContent);

// console.dir("------------------------------------------------------------------- 1")
// console.dir(classExamplesData)
}

// Let's render the index api file
var indexContent = ejs.render(templates['index'],
{entries:classNames, isClass:isClass, isFunction:isFunction, isProperty:isProperty, format:format});
// Write out the api index to disk
fs.writeFileSync(format("%s/%s.rst", outputDirectory, "index"), indexContent);



// console.dir(Object.keys(dataObjects))
}


// Render all the classes that are decorated
renderAllTemplates(outputDirectory, templates, dataObjects, testObjects);

// // Let's generate rendered templates for each method
// var renderedContent = ejs.render(templates.method, {});
// console.log("===========================================================================")
// console.dir(renderedContent)

// console.log(testObjects.admin.validateCollection[0].code)

// console.dir("========================================================================")
// console.dir(dataObjects)
// console.dir(require('uglify-js').parser)

// console.dir("========================================================================")
// console.dir(testObjects.admin.validateCollection[0].code)

// console.dir("==========================================================================")
// console.dir(parseJS.parse(testObjects.admin.validateCollection[0].code))
// var a = parseJS.parse(testObjects.admin.validateCollection[0].code);
// var b = parseJS.tokenizer(testObjects.admin.validateCollection[0].code);

// // console.dir("==========================================================================")
// // console.dir(b)
// // console.dir(a[1])
//
// var keepTokens = [];
// var token = null;
// while((token = b()).type != 'eof') {
// console.dir(token)
// }


// var docDirectory = "./build";
// // Fetch all the json objects
// var files = fs.readdirSync(docDirectory);
// // Print all json objects
// for(var i = 0; i < files.length; i++) {
// var file = files[i];
//
// if(file.indexOf('.json') != -1) {
// var jsonFile = fs.readFileSync(docDirectory + "/" + file);
// var object = JSON.parse(jsonFile.toString());
// console.log("====================================================== Content of :: " + file);
// if(Array.isArray(object)) {
// for(var i = 0; i < object.length; i++) {
// var item = object[i];
// console.log("---------------------------------------------------- item");
// console.dir(item);
// // console.dir(item.tags)
// }
// }
// // console.dir(object);
// }
// }
64 changes: 51 additions & 13 deletions dev/tools/doc-templates/class.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,63 @@ for(var i = 0; i < entries.length; i++) {
// Write out the text
%><%- format("%s\n\n", fullDescription) %><%
%><%= format(".. js:attribute:: %s %s [%s]\n\n", attributeName, type, getterSetters.join("|")) %><%
// If we have examples render them
if(examples != null && examples[attributeName]) {
%><%= format("**Examples**\n\n") %><%
var examplesArray = examples[attributeName];
// Iterate over all the examples
for(var ei = 0; ei < examplesArray.length; ei++) {
// Fetch an example
var example = examplesArray[ei];
var code = example.code;
code = code.replace(", ssl:useSSL", "")
.replace("native_parser: native_parser", "native_parser: false")
.replace(/test\.ok/g, "assert.ok")
.replace(/test\.equal/g, "assert.equal")
.replace(/test\.deepEqual/g, "assert.deepEqual")
.replace(/\n[ |\t]*test\.done\(\)\;/, "");
// Split and adjust code
var codeLines = code.split(/\n/);
for(var ci = 0; ci < codeLines.length; ci++) {
codeLines[ci] = " " + codeLines[ci];
}
var fullDescription = example.description.full;
fullDescription = fullDescription.replace(/\<pre\>\<code\>/g, ".. code-block:: javascript\n\n ")
.replace(/\<\/code\>\<\/pre\>/g, "")
.replace(/\<h2\>|\<\/h2\>/g, "**")
.replace(/\<p\>|\<\/p\>/g, "")
.replace(/\<br[ ]*\>|\<\/br[ ]*\>|\<br[ ]*\/\>/g, "\n");
// Split up and move
var fullDescriptionLines = fullDescription.split(/\n/);
for(var ci = 0; ci < fullDescriptionLines.length; ci++) {
fullDescriptionLines[ci] = " " + fullDescriptionLines[ci];
}
// Starting template Lines
var startingTemplateLines = [
" var Db = require('mongodb').Db,",
" Server = require('mongodb').Server,",
" ObjectID = require('mongodb').ObjectID,",
" assert = require('assert');\n\n"
];
// Let's render it
%><%- format("%s\n\n", fullDescriptionLines.join("\n")) %><%
%><%- format(" .. code-block:: javascript\n\n%s%s\n\n", startingTemplateLines.join("\n"), codeLines.join("\n")) %><%
}
}
}
}
for(var i = 0; i < entries.length; i++) {
// for(var i = 0; i < 4; i++) {
// console.log("---------------------------------------------------------------")
// console.dir(entries[i])
// If it's a function parse it
if(isFunction(entries[i])) {
var paramsStrings = [];
var paramNames = [];
// console.log("-------------------------------------------------------------- 0")
// console.dir(entries[i].tags)
for(var ti = 0; ti < entries[i].tags.length; ti++) {
// Get the current tag
Expand All @@ -102,8 +145,6 @@ for(var i = 0; i < entries.length; i++) {
// Reformat any optional parameters from ,[] to [,]
var paramsString = paramNames.join(", ").replace(/\, \[/, "[, ");
// Write out the methods
// %><%- format("\n%s\n", entries[i].description.full.replace(/<[^>]+>/g, '')) %><%
var fullDescription = entries[i].description.full;
fullDescription = fullDescription.replace(/\<pre\>\<code\>/g, ".. code-block:: javascript\n\n ")
.replace(/\<\/code\>\<\/pre\>/g, "")
Expand All @@ -120,8 +161,6 @@ for(var i = 0; i < entries.length; i++) {
if(examples != null && examples[entries[i].ctx.name]) {
%><%= format("**Examples**\n\n") %><%
var examplesArray = examples[entries[i].ctx.name];
// console.log("------------------------------------------------------- EXAMPLES ARRAY")
// console.dir(examplesArray)
// Iterate over all the examples
for(var ei = 0; ei < examplesArray.length; ei++) {
// Fetch an example
Expand Down Expand Up @@ -157,11 +196,10 @@ for(var i = 0; i < entries.length; i++) {
var startingTemplateLines = [
" var Db = require('mongodb').Db,",
" Server = require('mongodb').Server,",
" ObjectID = require('mongodb').ObjectID,",
" assert = require('assert');\n\n"
];
// console.log("------------------------------------------------------- EXAMPLE")
// console.dir(example)
// Let's render it
%><%- format("%s\n\n", fullDescriptionLines.join("\n")) %><%
%><%- format(" .. code-block:: javascript\n\n%s%s\n\n", startingTemplateLines.join("\n"), codeLines.join("\n")) %><%
Expand Down
10 changes: 6 additions & 4 deletions lib/mongodb/bson/objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ObjectID.prototype.get_inc = function() {
* Update the ObjectID index used in generating new ObjectID's on the driver
*
* @return {Number} returns next index value.
* @api public
* @api private
*/
ObjectID.prototype.getInc = function() {
return this.get_inc();
Expand All @@ -88,7 +88,7 @@ ObjectID.prototype.getInc = function() {
*
* @param {Number} [time] optional parameter allowing to pass in a second based timestamp.
* @return {String} return the 12 byte id binary string.
* @api public
* @api private
*/
ObjectID.prototype.generate = function(time) {
if ('number' == typeof time) {
Expand Down Expand Up @@ -136,7 +136,7 @@ ObjectID.prototype.toHexString = function() {
* Converts the id into a 24 byte hex string for printing
*
* @return {String} return the 24 byte hex string representation.
* @api public
* @api private
*/
ObjectID.prototype.toString = function() {
return this.toHexString();
Expand All @@ -156,7 +156,9 @@ ObjectID.prototype.inspect = ObjectID.prototype.toString;
* @return {String} return the 24 byte hex string representation.
* @api private
*/
ObjectID.prototype.toJSON = ObjectID.prototype.toString;
ObjectID.prototype.toJSON = function() {
return this.toHexString();
};

/**
* Compares the equality of this ObjectID with `otherID`.
Expand Down
Loading

0 comments on commit 1d4c51f

Please sign in to comment.