Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/annotation/annotations/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ export default function group () {
return {
name: 'group',

parse (text) {
return [text.trim().toLowerCase()]
parse (text, info) {
let lines = text.trim().split('\n')
let slug = lines[0].trim().toLowerCase()
let description = lines.splice(1).join('\n').trim()
if (description) {
info.groupDescriptions = info.groupDescriptions || {}
info.groupDescriptions[slug] = description
}
return [slug]
},

default () {
Expand Down
21 changes: 21 additions & 0 deletions src/annotation/annotations/groupDescription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* `@groupDescriptions` is should not be used on its own.
*
* It gets filled automatically from the lines following the `@group` annotation.
*
* @group example
* This is a group description. It describes the group.
* It can be split across multiple lines.
*
* {
* 'groupDescriptions': {
* 'example': 'This is a group description. It describes the group.\nIt can be split across multiple lines.'
* }
* }
*/

export default function groupDescriptions () {
return {
name: 'groupDescriptions',
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please just add a comment in here explaining why it was added, and that it's not a real annotation etc. basically we shouldn't add it, but I don't want to delay your feature further, our tests will need a good refactor anyway.

1 change: 1 addition & 0 deletions src/annotation/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = [
require('./deprecated.js').default,
require('./example.js').default,
require('./group.js').default,
require('./groupDescription.js').default,
require('./ignore.js').default,
require('./link.js').default,
require('./name.js').default,
Expand Down
2 changes: 1 addition & 1 deletion test/annotations/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('#AnnotationsApi', function () {
it('should include the right number of annotations', function () {
assert.equal(
Object.keys(api.list).length,
21
22
)
})
})
8 changes: 8 additions & 0 deletions test/annotations/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ describe('#group', function () {
assert.deepEqual(group.parse('group'), ['group'])
assert.deepEqual(group.parse('GRoup'), ['group'])
})

it('should parse a description from subsequent lines', function () {
var item = {}
assert.deepEqual(group.parse('group\ndescription', item), ['group'])
assert.deepEqual(item, {'groupDescriptions': {
'group': 'description'
}})
})
})
Loading