Skip to content

Commit

Permalink
Ass support for group descriptions (#39)
Browse files Browse the repository at this point in the history
- Collect groupDescriptions in ctx
- Parse groupDescriptions as markdown
  • Loading branch information
xi authored and pascalduez committed Apr 7, 2019
1 parent 26e146f commit 899ccbf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/groupName.js
Expand Up @@ -4,10 +4,11 @@
* Compute a `groupName` object from `group` array with slug as key and
* title as value.
*
* Also compute a `groups` property in `ctx`.
* Also compute a `groups` and `groupDescriptions` properties in `ctx`.
*/
module.exports = function groupName (ctx) {
ctx.groups = ctx.groups || {}
ctx.groupDescriptions = ctx.groupDescriptions || {}

// Lowercase the slugs.
Object.keys(ctx.groups).forEach(function (slug) {
Expand All @@ -26,6 +27,7 @@ module.exports = function groupName (ctx) {
group[slug] = ctx.groups[slug] = slug
}
})
Object.assign(ctx.groupDescriptions, item.groupDescriptions)

item.groupName = group
})
Expand Down
6 changes: 6 additions & 0 deletions src/markdown.js
Expand Up @@ -81,5 +81,11 @@ module.exports = function markdown (ctx) {
if ('since' in item) {
item.since = item.since.map(applyKey(md, 'description'))
}

if ('groupDescriptions' in item) {
for (let k of Object.keys(item.groupDescriptions)) {
item.groupDescriptions[k] = marked(item.groupDescriptions[k])
}
}
})
}
10 changes: 10 additions & 0 deletions test/fixture/groupName/expected.json
Expand Up @@ -4,6 +4,10 @@
"foo": "Foo group",
"bar": "Bar group"
},
"groupDescriptions": {
"foo": "description",
"bar": "description"
},
"data": [{
"description": "Test: function group undefined.\n",
"context": {
Expand All @@ -28,6 +32,9 @@
"group": [
"foo"
],
"groupDescriptions": {
"foo": "description"
},
"access": [
"public"
],
Expand All @@ -43,6 +50,9 @@
"group": [
"bar"
],
"groupDescriptions": {
"bar": "description"
},
"access": [
"public"
],
Expand Down
6 changes: 6 additions & 0 deletions test/fixture/groupName/input.json
Expand Up @@ -25,6 +25,9 @@
"group": [
"foo"
],
"groupDescriptions": {
"foo": "description"
},
"access": [
"public"
]
Expand All @@ -37,6 +40,9 @@
"group": [
"bar"
],
"groupDescriptions": {
"bar": "description"
},
"access": [
"public"
]
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/markdown/expected.json
Expand Up @@ -34,6 +34,9 @@
},
"content": {
"description": "<p>This should be parsed as Markdown</p>\n"
},
"groupDescriptions": {
"group": "<p>description</p>\n"
}
}]
}
3 changes: 3 additions & 0 deletions test/fixture/markdown/input.json
Expand Up @@ -37,6 +37,9 @@
},
"content": {
"description": "This should be parsed as Markdown"
},
"groupDescriptions": {
"group": "description"
}
}]
}

0 comments on commit 899ccbf

Please sign in to comment.