From e5fc7f726628b450afac4e6f6900ffc1fa365b95 Mon Sep 17 00:00:00 2001 From: christopherthielen Date: Sat, 1 Nov 2014 14:11:08 -0500 Subject: [PATCH] feat(parameters): add parameter property support - If a @param has a dot in the name, move it to a properties array on the parent param. - Render a nested table in the param's details with all the param's properties. - Refactor parameter TR dom output to a function. Closes #86 --- src/ngdoc.js | 101 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/src/ngdoc.js b/src/ngdoc.js index 191bea7..fb82d7b 100644 --- a/src/ngdoc.js +++ b/src/ngdoc.js @@ -412,11 +412,21 @@ Doc.prototype = { default: match[5] }; // if param name is a part of an object passed to a method - // mark it, so it's not included in the rendering later - if(param.name.indexOf(".") > 0){ + // move it to a nested property of the parameter. + var dotIdx = param.name.indexOf("."); + if(dotIdx > 0){ param.isProperty = true; + var paramName = param.name.substr(0, dotIdx); + var propertyName = param.name.substr(dotIdx + 1); + param.name = propertyName; + var p = self.param.filter(function(p) { return p.name === paramName; })[0]; + if (p) { + p.properties = p.properties || []; + p.properties.push(param); + } + } else { + self.param.push(param); } - self.param.push(param); } else if (atName == 'returns' || atName == 'return') { match = text.match(/^\{([^}]+)\}\s+(.*)/); if (!match) { @@ -566,42 +576,59 @@ Doc.prototype = { dom.html(''); dom.html(''); dom.html(''); - for(var i=0;i)/); - if (param.optional) { - name += '
(optional)
'; - } - dom.html(''); - dom.html('' + name + ''); - dom.html(''); - for(var j=0;j'); - dom.text(type); - dom.html(''); - } + var limit = types.length - 1; + if(types.charAt(limit) == ')' && types.charAt(limit-1) != '(') { + types = types.substr(0,limit); + } + types = types.split(/\|(?![\(\)\w\|\s]+>)/); + if (param.optional) { + name += '
(optional)
'; + } + dom.html(''); + dom.html('' + name + ''); + dom.html(''); + for(var j=0;j'); + dom.text(type); + dom.html(''); + } - dom.html(''); - var description = ''; - description += param.description; - if (param.default) { - description += '

(default: ' + param.default + ')

'; - } - description += ''; - dom.html(description); - dom.html(''); - }; + dom.html(''); + dom.html(''); + dom.html(param.description); + if (param.default) { + dom.html('

(default: ' + param.default + ')

'); + } + if (param.properties) { +// dom.html(''); + dom.html('
'); + dom.html(''); + dom.html(''); + dom.html(''); + dom.html(''); + dom.html(''); + dom.html(''); + dom.html(''); + dom.html(''); + processParams(param.properties); + dom.html(''); + dom.html('
PropertyTypeDetails
'); + } + dom.html(''); + dom.html(''); + }; + } dom.html(''); dom.html(''); }