build(aio): truncate API overview parameters at one line

This commit is contained in:
Peter Bacon Darwin
2017-07-12 22:20:55 +01:00
committed by Igor Minar
parent a7ea0086ee
commit 998049ec9b
6 changed files with 40 additions and 8 deletions

View File

@ -0,0 +1,13 @@
module.exports = function() {
return {
name: 'truncateFirstLine',
process: function(str) {
const parts = str && str.split && str.split(/\r?\n/);
if (parts && parts.length > 1) {
return parts[0] + '...';
} else {
return str;
}
}
};
};

View File

@ -0,0 +1,19 @@
var factory = require('./truncateFirstLine');
describe('truncateFirstLine filter', function() {
var filter;
beforeEach(function() { filter = factory(); });
it('should be called "truncateFirstLine"',
function() { expect(filter.name).toEqual('truncateFirstLine'); });
it('should return the whole string if only one line', function() {
expect(filter.process('this is a pretty long string that only exists on one line'))
.toEqual('this is a pretty long string that only exists on one line');
});
it('should return the first line and an ellipsis if there is more than one line', function() {
expect(filter.process('some text\n \nmore text\n \n')).toEqual('some text...');
});
});