Skip to content

Commit

Permalink
fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
onury committed Dec 29, 2017
1 parent 6a7d8d0 commit f54e4ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
51 changes: 42 additions & 9 deletions lib/web/core.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,21 +772,54 @@
};
};

// ---------------------------

utils.listType = function (list) {
/**
* Gets HTML formatted, delimeted code tags.
* @memberof docma.utils
* @name getCodeTags
* @function
*
* @param {Array} list - String list of values.
* @param {String} [delimeter=","] - String delimeter.
*
* @returns {String}
*/
utils.getCodeTags = function (list, demileter) {
return list.map(function (item) {
return utils._wrapEscapeCode(item); // '<code>' + item + '</code>';
}).join(', ');
}).join(demileter || ',');
};

utils.listTypeDesc = function (list) {
/**
* Gets HTML formatted list of types from the given symbols list. Type
* items are wrapped with code tags. If multiple, formatted as an HTML
* unordered list.
* @memberof docma.utils
* @name getFormattedTypeList
* @function
*
* @param {Array} list - List of symbols.
* @param {Object} [options] - Format options.
* @param {String} [options.delimeter="|"] - Types delimeter.
* @param {Boolean} [options.descriptions=true] - Whether to include descriptions.
* @param {String} [options.descDelimeter=" — "] - Description delimiter.
*
* @returns {String}
*/
utils.getFormattedTypeList = function (list, options) {
if (!list || list.length === 0) return '';
var desc;

var opts = options || {};
var delim = opts.delimeter || '|';
var addDesc = typeof opts.descriptions !== 'boolean' ? true : opts.descriptions;
var descDelim = opts.descDelimeter || '&nbsp;&nbsp;—&nbsp;&nbsp;';

var desc = '';
var pList = list.map(function (item) {
desc = utils.parse(item.description || '', { keepIfSingle: true });
if (desc) desc = '&nbsp;&nbsp;—&nbsp;&nbsp;' + desc;
return utils._wrapEscapeCode(item.type.names.join('|')) + desc; // '<code>' + item.type.names.join('|') + '</code>' + desc;
if (addDesc) {
desc = utils.parse(item.description || '', { keepIfSingle: true });
if (desc) desc = descDelim + desc;
}
return utils._wrapEscapeCode(item.type.names.join(delim)) + desc; // '<code>' + item.type.names.join('|') + '</code>' + desc;
});
if (pList.length > 1) {
return '<ul>\n' + pList.join('</li>\n<li>') + '\n</ul>';
Expand Down
6 changes: 3 additions & 3 deletions templates/default/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@
})
.addFilter('$extends', function (symbol) {
var ext = Array.isArray(symbol) ? symbol : symbol.augments;
return docma.utils.listType(ext);
return docma.utils.getCodeTags(ext, ', ');
})
.addFilter('$returns', function (symbol) {
var returns = Array.isArray(symbol) ? symbol : symbol.returns;
return docma.utils.listTypeDesc(returns);
return docma.utils.getFormattedTypeList(returns);
})
.addFilter('$exceptions', function (symbol) {
var exceptions = Array.isArray(symbol) ? symbol : symbol.exceptions;
return docma.utils.listTypeDesc(exceptions);
return docma.utils.getFormattedTypeList(exceptions);
})
// non-standard JSDoc directives are stored in `.tags` property of a
// symbol. We also add other properties such as .access (if not public),
Expand Down

0 comments on commit f54e4ac

Please sign in to comment.