Skip to content

Commit

Permalink
fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Nov 25, 2014
1 parent f3aaf64 commit 5a05e97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
22 changes: 14 additions & 8 deletions lib/tags/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ var typer = require('./helpers/typer'),
namer = require('./helpers/namer'),
tnd = require('./helpers/typeNameDescription');

// go through the types and get the first one that has options
var getOptions = function(param){
for(var i =0; i < param.types.length; i++) {
if( param.types[i].options ) {
return param.types[i].options;
}
}
};

// go through the types and return the first one that has params
var getParams = function(param){
for(var i =0; i < param.types.length; i++) {
if( param.types[i].params ) {
Expand All @@ -34,7 +35,7 @@ var typer = require('./helpers/typer'),
return options[i];
}
}
var option = {name: name}
var option = {name: name};
options.push(option);
return option;
},
Expand Down Expand Up @@ -161,18 +162,23 @@ var typer = require('./helpers/typer'),
if(!data.name){
console.log("LINE: \n" + line + "\n does not match @option [{TYPE}] NAME DESCRIPTION");
}
var params = getParams(prevParam);
var options = getOptions(prevParam);



// try to get a params or options object
var params = getParams(prevParam),
options = getOptions(prevParam);

if(!options && !params){
console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to.");
return;
if(prevParam.types[0]) {
options = (prevParam.types[0].options = []);
} else {
console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to.");
return;
}
}
// get the named one
var option = getOrMakeOptionByName(options || params, data.name);

// add to it
setOptionData(option, data);

return option;
Expand Down
18 changes: 15 additions & 3 deletions lib/tags/option_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("documentjs/lib/tags/option",function(){

it("@option",function(){

var obj = {}
var obj = {};
param.add.call(obj,"@param {{name: String, foo}=} thing a description");
option.add.call(obj, "@option name name description");
option.add.call(obj, "@option {Bar} [foo=thing] foo description");
Expand Down Expand Up @@ -38,7 +38,7 @@ describe("documentjs/lib/tags/option",function(){

it("@option on Object",function(){

var obj = {}
var obj = {};
param.add.call(obj,"@param {Object} thing a description");
option.add.call(obj, "@option {String} name name description");
option.add.call(obj, "@option {Bar} [foo=thing] foo description");
Expand Down Expand Up @@ -157,9 +157,21 @@ describe("documentjs/lib/tags/option",function(){
[
{type: "Foo", description: "Foo description"},
{type: "Bar", description: "Bar description"}
])
]);

});

it("@option can add on a @param that is not an object (#72)", function(){
var obj = {};
param.add.call(obj,"@param {Something} thing a description");
option.add.call(obj, "@option {Foo} foo foo description");

assert.deepEqual(obj.params[0].types[0].options,
[
{name: "foo", types: [{type:"Foo"}], description: "foo description"}
]);

});


});

0 comments on commit 5a05e97

Please sign in to comment.