Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
Add all the past work to attribute definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemke committed Mar 26, 2016
1 parent f14ee16 commit 467f37e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 41 deletions.
16 changes: 11 additions & 5 deletions angular-template/html/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ <h5>Attributes:</h5>
<tr ht-repeat="attr in attributes">
<td class="name" nowrap>{{ attr.name }}</td>
<td class="type"><span class="param-type">
{{ attr.type && attr.type.names.join(" | ") }}
{{ attr.typeDefinition }}
</span></td>
<td class="description last">{{ marked(attr.description||'') }}</td>
<td class="description last">
<span ht-if="attr.description">
{{ marked(attr.description.replace(/\{@link (.*?)(#.*?)?\}/g, '<a href="$1.html$2">$1$2</a>')||'') }}
</span>
</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -186,9 +190,11 @@ <h5>Returns:</h5>
</thead>
<tbody>
<tr ht-repeat="ret in func.returns">
<td class="type"><span class="param-type">
{{ ret.type && ret.type.names.join(" | ").replace(new RegExp( String.fromCharCode(60), "g" ), "&lt;") }}
</span></td>
<td class="type">
<span class="param-type">
{{ ret.type && ret.type.names.join(" | ").replace(new RegExp( String.fromCharCode(60), "g" ), "&lt;") }}
</span>
</td>
<td class="description last">
<span ht-if="ret.description">
{{ ret.description.replace(/\{@link (.*?)(#.*?)?\}/g, '<a href="$1.html$2">$1$2</a>') }}
Expand Down
78 changes: 42 additions & 36 deletions common/plugins/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ exports.defineTags = function(dictionary) {
canHaveType: true,
canHaveName: true,
onTagged: function(doclet, tag) {
if (!doclet.attributes) { doclet.attributes = []; }
doclet.attributes.push(tag.value);
doclet.attributes = parseParamTypes(doclet.attributes, tag);
}
})
.synonym('attr');
Expand All @@ -27,40 +26,7 @@ exports.defineTags = function(dictionary) {
canHaveType: true,
canHaveName: true,
onTagged: function(doclet, tag) {
if (!doclet.params) {
doclet.params = [];
}

var defaultTypes = ['boolean', 'string', 'expression', '*', 'mixed', 'number', 'null', 'undefined', 'function',
'{}', 'object', '[]', 'array'];

var typeRegex = new RegExp(/\{(.*?[^\[\]])?(\[\])?\}.*?/);
var matches = typeRegex.exec(tag.text);

var types = matches[1].split('|');
matches[2] = (matches[2] || '');
var parsedTypeDefinition = '';

var i = 0;
for (; i < types.length; i++) {
var type = types[i];

if (i > 0) {
parsedTypeDefinition += '|';
}

if (defaultTypes.indexOf(type) !== -1 || type[0] === '"') {
parsedTypeDefinition += type + matches[2];
} else {
parsedTypeDefinition += '<a href="' + matches[1] + '.html">' + matches[1] + matches[2] + '</a>';
}
}

doclet.params.push({
typeDefinition: parsedTypeDefinition,
name: tag.value.name,
description: tag.value.description
});
doclet.params = parseParamTypes(doclet.params, tag);
}
});

Expand Down Expand Up @@ -120,3 +86,43 @@ exports.defineTags = function(dictionary) {
}
});
};

function parseParamTypes(docletParams, tag) {
if (!docletParams) {
docletParams = [];
}

var defaultTypes = ['boolean', 'string', 'expression', '*', 'mixed', 'number', 'null', 'undefined', 'function',
'{}', 'object', '[]', 'array', 'void'];
var defaultTypeStarts = ['\'', '"', '[', '{'];

var typeRegex = new RegExp(/\{(.*?[^\[\]])?(\[\])?\}.*?/);
var matches = typeRegex.exec(tag.text);

var types = matches[1].split('|');
matches[2] = (matches[2] || '');
var parsedTypeDefinition = '';

var i = 0;
for (; i < types.length; i++) {
var type = types[i];

if (i > 0) {
parsedTypeDefinition += '|';
}

if (defaultTypes.indexOf(type) !== -1 || defaultTypeStarts.indexOf(type[0]) !== -1) {
parsedTypeDefinition += type + matches[2];
} else {
parsedTypeDefinition += '<a href="' + matches[1] + '.html">' + matches[1] + matches[2] + '</a>';
}
}

docletParams.push({
typeDefinition: parsedTypeDefinition,
name: tag.value.name,
description: tag.value.description
});

return docletParams;
}

0 comments on commit 467f37e

Please sign in to comment.