|
| 1 | +var tnd = require("bit-docs-type-annotate").typeNameDescription; |
| 2 | + |
| 3 | + // go through the types and get the first one that has options |
| 4 | + var getOptions = function(param){ |
| 5 | + if(!param.types) { |
| 6 | + return; |
| 7 | + } |
| 8 | + for(var i =0; i < param.types.length; i++) { |
| 9 | + if( param.types[i].options ) { |
| 10 | + return param.types[i].options; |
| 11 | + } |
| 12 | + } |
| 13 | + }; |
| 14 | + // go through the types and return the first one that has params |
| 15 | + var getParams = function(param){ |
| 16 | + if(!param.types) { |
| 17 | + return; |
| 18 | + } |
| 19 | + for(var i =0; i < param.types.length; i++) { |
| 20 | + if( param.types[i].params ) { |
| 21 | + return param.types[i].params; |
| 22 | + } |
| 23 | + } |
| 24 | + }; |
| 25 | + |
| 26 | + // find matching type |
| 27 | + var getType = function(types, type){ |
| 28 | + for(var i =0; i < types.length; i++) { |
| 29 | + if( types[i].type === type ) { |
| 30 | + return types[i]; |
| 31 | + } |
| 32 | + } |
| 33 | + }; |
| 34 | + |
| 35 | + var getOrMakeOptionByName = function(options, name){ |
| 36 | + for(var i =0; i < options.length; i++) { |
| 37 | + if( options[i].name === name ) { |
| 38 | + return options[i]; |
| 39 | + } |
| 40 | + } |
| 41 | + var option = {name: name}; |
| 42 | + options.push(option); |
| 43 | + return option; |
| 44 | + }, |
| 45 | + setOptionData = function(option, data){ |
| 46 | + option.description = data.description; |
| 47 | + |
| 48 | + for(var prop in data){ |
| 49 | + option[prop] = data[prop]; |
| 50 | + } |
| 51 | + }; |
| 52 | + |
| 53 | + |
| 54 | + module.exports = { |
| 55 | + |
| 56 | + addMore: function( line, last ) { |
| 57 | + if ( last ) last.description += "\n" + line; |
| 58 | + }, |
| 59 | + add: function( line, tagData ) { |
| 60 | + |
| 61 | + var noNameData = tnd(line, true), |
| 62 | + data = tnd(line); |
| 63 | + // we should look to find something matching |
| 64 | + var locations = [this]; |
| 65 | + // only process this type of option if there is one value |
| 66 | + if(noNameData.types && noNameData.types.length == 1) { |
| 67 | + var typeData = noNameData.types[0]; |
| 68 | + for(var i = 0 ; i < locations.length; i++){ |
| 69 | + var obj = locations[i]; |
| 70 | + if(obj){ |
| 71 | + if(!obj.types){ |
| 72 | + obj.types = []; |
| 73 | + } |
| 74 | + var type = getType(obj.types, typeData.type); |
| 75 | + if(type){ |
| 76 | + // copy description |
| 77 | + type.description = noNameData.description; |
| 78 | + // copy any additional type info |
| 79 | + for(var prop in typeData){ |
| 80 | + type[prop] = typeData[prop]; |
| 81 | + } |
| 82 | + return type; |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + }; |
0 commit comments