Skip to content

Commit

Permalink
fixes, tweaks, functionality
Browse files Browse the repository at this point in the history
- Fixes
  - fixed incorrect default behavior which was to use all symbols.  now defaults to ignoring internal/private functions as before.  respects `@private` tag.
  - fixed problem wherein function-level `@description` would be duplicated in a `@returns` tag having no description of its own
  - fixed invalid `.jshintrc` and removed unused `jshint-config.json`
  - fixed bad formatting (extra comma) when displaying a member or parameter w/o a `@description`
- Enhancements
  - support for `@example` tag
  - support for `@property` tag
  - type support for both `@property` tag and members
- Display tweaks
  - separated `@author` tag display from `@license` tag display in template
  - types now display in `monospace`
  - class displays as title "Class: <classname>" to differentiate from module
  • Loading branch information
Christopher Hiller committed Aug 23, 2014
1 parent ede0366 commit 2131b11
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 59 deletions.
7 changes: 2 additions & 5 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
"node": true,
"noempty": true,
"nonew": true,
"globals": {
"define": true,
"should": false
},
"predef":
[
"after",
Expand All @@ -29,7 +25,8 @@
"it",
"unescape",
"par",
"each"
"each",
"define"
],
"smarttabs": true,
"trailing": false,
Expand Down
3 changes: 2 additions & 1 deletion jsdox.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function generateForDir(filename, destination, templateDir, cb, fileCb) {
console.log(file + ' Analyzed: ', util.inspect(analyze(result), false, 20));
}

var data = analyze(result),
var data = analyze(result, argv),
output = generateMD(data, templateDir);

if (output) {
Expand Down Expand Up @@ -171,6 +171,7 @@ function loadConfigFile(file, callback){
var config;

//check to see if file exists
file = path.resolve(process.cwd(), file);
fs.exists(file, function(exists) {
if (exists) {
try {
Expand Down
38 changes: 0 additions & 38 deletions jshint-config.json

This file was deleted.

23 changes: 16 additions & 7 deletions lib/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Transforms the AST into a form that represents a single file with modules and their functions.
*
* @param {Object} ast
* @param {Object} argv Command-line args
* @returns {Object}
*
* @example
Expand Down Expand Up @@ -44,7 +45,7 @@
* version: ''
* }
*/
module.exports = function(ast) {
module.exports = function(ast, argv) {
var result = {
functions: [],
methods: [],
Expand All @@ -62,7 +63,8 @@ module.exports = function(ast) {
},
currentModule = null,
currentClass = null,
currentFunction = null;
currentFunction = null,
ignoreInternal = !argv.All;

function initGlobalModule() {
var global = {};
Expand All @@ -79,6 +81,7 @@ module.exports = function(ast) {
}

ast.forEach(function (tag) {
if (ignoreInternal && isInternal(tag)) { return; }
switch (tag.kind) {
case 'file':
result.license = tag.license;
Expand All @@ -103,14 +106,17 @@ module.exports = function(ast) {
// For param details
fn.params.forEach(setPipedTypesString);
fn.returns = tag.returns || [];
fn.returns.forEach(setPipedTypesString);
fn.returns.forEach(function(ret) {
setPipedTypesString(ret);
ret.description = ret.description || false;
});
// To avoid reaching to the parent for these fields
fn.version = tag.version || false;
fn.fires = tag.fires || [];
fn.description = tag.description;
fn.deprecated = tag.deprecated || false;
fn.internal = isInternal(fn.name);
fn.moduleName = currentModule ? currentModule.name : '';
fn.examples = tag.examples || [];
currentFunction = fn;
if (currentClass) {
currentClass.methods.push(fn);
Expand All @@ -133,6 +139,7 @@ module.exports = function(ast) {
case 'member':
if (currentClass && tag.undocumented !== true) {
currentClass.members.push(tag);
setPipedTypesString(tag);
} else if (tag.scope === 'inner' && tag.undocumented !== true) {
result.members.push({member: tag.name});
result.hasMembers = true;
Expand All @@ -148,6 +155,7 @@ module.exports = function(ast) {
case 'module':
var module = {};
module.name = tag.name;
module.examples = tag.examples || [];
module.functions = [];
module.classes = [];
module.description = tag.description;
Expand All @@ -164,8 +172,9 @@ module.exports = function(ast) {
var klass = {};
klass.name = tag.name;
klass.methods = [];
klass.members = [];
klass.description = tag.description;
klass.members = tag.properties || [];
klass.members.forEach(setPipedTypesString);
result.classes.push(klass);
if (currentModule) {
currentModule.classes.push(klass);
Expand Down Expand Up @@ -194,6 +203,6 @@ function setPipedTypesString(node) {
node.typesString = node.type.names.join(' | ');
}

function isInternal(name){
return name.lastIndexOf('_', 0) === 0;
function isInternal(tag){
return tag && ((tag.name && tag.name.lastIndexOf('_', 0) === 0) || tag.private);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"lib"
],
"scripts": {
"test": "jshint --config jshint-config.json jsdox.js bin/* test/* fixtures/* && node_modules/.bin/mocha;"
"test": "jshint --config .jshintrc jsdox.js bin/* test/* fixtures/* && node_modules/.bin/mocha;"
},
"preferGlobal": true,
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions templates/class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{{#description}}{{{description}}}{{/description}}

{{#members}}
**{{name}}** - {{{description}}}
**{{name}}**: {{#typesString}}`{{typesString}}`{{/typesString}} {{#description}}, {{{description}}}{{/description}}
{{/members}}
{{#methods}}
{{> function}}
{{/methods}}
{{/methods}}
13 changes: 11 additions & 2 deletions templates/file.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
{{/members}}
{{/hasMembers}}

{{#examples}}
**Example:**
```js
{{{examples}}}
```

{{/examples}}
---

{{#functions}}
{{> function}}

{{/functions}}
{{#classes}}
{{> class}}
Class: {{> class}}

{{/classes}}

Expand All @@ -38,7 +45,9 @@

{{#copyright}}*{{copyright}}*{{/copyright}}

{{#license}}**License:** {{license}} {{/license}}{{#author}}{{author}}{{/author}}
{{#author}}**Author:** {{author}}{{/author}}

{{#license}}**License:** {{license}} {{/license}}

{{#overview}}**Overview:** {{{overview}}}{{/overview}}

Expand Down
14 changes: 11 additions & 3 deletions templates/function.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ Deprecated: {{{deprecated}}}

{{/hasParams}}
{{#params}}
**{{name}}**: {{#typesString}}{{typesString}}, {{/typesString}}{{#description}}{{{description}}}{{/description}}
**{{name}}**: {{#typesString}}`{{typesString}}`{{/typesString}}{{#description}}, {{{description}}}{{/description}}

{{/params}}
{{#fires}}
**Fires**: {{.}}

{{/fires}}
{{#returns}}
**Returns**: {{#typesString}}{{typesString}}, {{/typesString}}{{#description}}{{{description}}}{{/description}}
{{/returns}}
**Returns**: {{#typesString}}`{{typesString}}`{{/typesString}}{{#description}}, {{{description}}}{{/description}}
{{/returns}}

{{#examples}}
**Example**:
```js
{{{examples}}}
```

{{/examples}}

0 comments on commit 2131b11

Please sign in to comment.