Skip to content

Commit ed17669

Browse files
committed
Overhaul code documentation
1 parent b2cdc93 commit ed17669

16 files changed

+276
-5
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
'/usage/',
2424
'/usage/modules.html',
2525
'/usage/requests.html',
26-
'/code/'
26+
'/code/classes/'
2727
]
2828
},
2929
evergreen: true

docs/.vuepress/jsdoc.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// YARN_SILENT=1 yarn jsdoc2md -f 'src/**/*' --private -l js --name-format --separators --template docs/.vuepress/jsdoctemplate.handlebars > docs/code/README.md
2+
const fs = require('fs')
3+
const path = require('path')
4+
const jsdoc2md = require('jsdoc-to-markdown')
5+
const handlebars = require('handlebars')
6+
7+
8+
function loadTemplate (templateName) {
9+
const relativeTemplateName = `docs/.vuepress/templates/jsdoc/${templateName}.handlebars`
10+
if (fs.existsSync(relativeTemplateName)) {
11+
const templateData = fs.readFileSync(relativeTemplateName, { encoding: 'utf-8' })
12+
return handlebars.compile(templateData)
13+
}
14+
15+
return null
16+
}
17+
18+
handlebars.registerHelper('jsDocBlock', function () {
19+
const template = loadTemplate(`kind.${this.kind}`)
20+
if (template) {
21+
return template(this)
22+
}
23+
24+
return `**MISSING JSDOC TEMPLATE FOR DOC BLOCK KIND ${this.kind}**`
25+
})
26+
27+
const dirs = ['classes', 'functions']
28+
dirs.forEach(dir => {
29+
const relDir = `docs/code/${dir}`
30+
if (!fs.existsSync(relDir))
31+
fs.mkdirSync(relDir)
32+
})
33+
34+
const templateData = jsdoc2md.getTemplateDataSync({
35+
files: path.resolve('src/**/*.js')
36+
})
37+
38+
documentClasses(templateData)
39+
// documentFunctions(templateData)
40+
41+
/**
42+
*
43+
* @param {Object} templateData
44+
*/
45+
function documentClasses (templateData) {
46+
const classes = templateData.reduce((classNames, identifier) => {
47+
if (identifier.kind === 'class') classNames.push(identifier.name)
48+
return classNames
49+
}, [])
50+
51+
const classTemplate = loadTemplate('class')
52+
53+
const classIndexData = {
54+
classes: {}
55+
}
56+
57+
for (const cls of classes) {
58+
classIndexData.classes[cls] = {
59+
name: cls,
60+
link: cls + '.html'
61+
}
62+
}
63+
64+
console.log(classIndexData)
65+
66+
classes.forEach(className => {
67+
const fileName = `docs/code/classes/${className}.md`
68+
const classData = templateData
69+
.filter(jsdocBlock => jsdocBlock.memberof === className)
70+
.sort((a, b) => {
71+
return a.order < b.order ? -1 : 1
72+
}).forEach(classData => {
73+
if (classData.kind === 'class') {
74+
classIndexData.classes[className].description = classData.description
75+
}
76+
})
77+
78+
console.log(`rendering ${className} to ${fileName}`)
79+
fs.writeFileSync(fileName, classTemplate({ className, classData }))
80+
})
81+
82+
console.log('rendering index for class documentation')
83+
fs.writeFileSync('docs/code/classes/README.md', loadTemplate('classindex')(classIndexData))
84+
}
85+
86+
/**
87+
*
88+
* @param {Object} templateData
89+
*/
90+
function documentFunctions (templateData) {
91+
const functionNames = templateData.reduce((functionNames, identifier) => {
92+
if (identifier.kind === 'function') functionNames.push(identifier.name)
93+
return functionNames
94+
}, [])
95+
96+
console.dir(functionNames)
97+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
16
# API
27

38
{{>main}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class {{ className }}
7+
8+
{{#each classData}}
9+
{{ jsDocBlock }}
10+
{{/each}}
11+
12+
__This is an autogenerated class documentation for {{ className }} __
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Available Classes
2+
3+
{{#each classes}}
4+
## {{ name }}
5+
6+
{{{ description }}}
7+
8+
<a href="{{ link }}">{{ name }}</a>
9+
{{/each}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{{ description }}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## {{ id }}
2+
3+
{{ description }}

docs/code/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/code/classes/Builder.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class Builder
7+
8+
9+
__This is an autogenerated class documentation for Builder __
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class FosJsRoutingRouter
7+
8+
9+
__This is an autogenerated class documentation for FosJsRoutingRouter __

docs/code/classes/JsonApiRouter.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class JsonApiRouter
7+
8+
9+
__This is an autogenerated class documentation for JsonApiRouter __

docs/code/classes/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Available Classes
2+
3+
## Builder
4+
5+
JsonApi-based module builder for Vuex
6+
7+
This module builder will create a vuex module based on the assumption of
8+
working with valid json api resources.
9+
10+
- the proposed json api 1.1 pagination style meta attributes
11+
(-> https://jsonapi.org/format/1.1/#fetching-pagination)
12+
13+
<a href="Builder.html">Builder</a>
14+
## FosJsRoutingRouter
15+
16+
Pluggable api router if you're using Symfony and the FosJsRouting Bundle
17+
18+
<a href="FosJsRoutingRouter.html">FosJsRoutingRouter</a>
19+
## JsonApiRouter
20+
21+
A simple router implementation querying a json:api endpoint which delivers all
22+
necessary route information
23+
24+
The endpoint must return a list of Route objects:
25+
26+
```json
27+
{
28+
"data": [
29+
{
30+
"type": "Route",
31+
"id": "api.route.list",
32+
"attributes": {
33+
"parameters": [],
34+
"url": "api/route",
35+
"method": "list"
36+
}
37+
},
38+
{
39+
"type": "Route",
40+
"id": "api.route.get",
41+
"attributes": {
42+
"parameters": [
43+
"id"
44+
],
45+
"url": "api/route/{id}",
46+
"method": "get"
47+
}
48+
}
49+
]
50+
}
51+
```
52+
53+
To initialize this router, simply `new` it with the desired fetch path,
54+
e.g. `new JsonApiRouter('/api/route')`.
55+
56+
<a href="JsonApiRouter.html">JsonApiRouter</a>
57+
## Route
58+
59+
60+
61+
<a href="Route.html">Route</a>
62+
## Router
63+
64+
Basic router implementation for the ResourcefulApi.
65+
66+
Automagically creating api bound modules builds on
67+
an understanding of the available routes. To
68+
easily instantiate a Store bound to an endpoint,
69+
route information for that endpoint must be provided.
70+
71+
Since every endpoint is implemented differently and
72+
the choice where this route information comes from
73+
should be left to the endpoint developer, this
74+
library only assumes that route loading is usually an
75+
asynchronous process which eventually returns and
76+
has a set of keyed-by-name `Route` objects in
77+
`this.routes`.
78+
79+
<a href="Router.html">Router</a>
80+
## StaticRouter
81+
82+
Static router
83+
84+
It may be desirable to not do an additional request
85+
for getting the api routes and instead bake them into
86+
the code. To this avail, the `StaticRouter` can be
87+
initialized with a POJO of { id, url, parameters }
88+
whereas parameters are parts of the url which can be replaced.
89+
90+
<a href="StaticRouter.html">StaticRouter</a>

docs/code/classes/Route.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class Route
7+
8+
9+
__This is an autogenerated class documentation for Route __

docs/code/classes/Router.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class Router
7+
8+
9+
__This is an autogenerated class documentation for Router __

docs/code/classes/StaticRouter.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar: auto
3+
displayAllHeaders: true
4+
activeHeaderLinks: true
5+
---
6+
# Class StaticRouter
7+
8+
9+
__This is an autogenerated class documentation for StaticRouter __

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"test": "yarn unit",
1414
"tdd": "yarn unit --watch",
1515
"lint": "eslint --ext .js,.vue src test/unit",
16-
"vuepress:apidoc": "YARN_SILENT=1 yarn jsdoc2md -f 'src/**/*' --private -l js --name-format --separators --template docs/.vuepress/jsdoctemplate.handlebars > docs/code/README.md",
17-
"vuepress:dev": "yarn vuepress:apidoc && vuepress dev docs",
18-
"vuepress:build": "yarn vuepress:apidoc && vuepress build docs"
16+
"prepublish": "node docs/.vuepress/jsdoc.js",
17+
"vuepress:dev": "vuepress dev docs",
18+
"vuepress:build": "vuepress build docs"
1919
},
2020
"dependencies": {
2121
"axios": "^0.*",
@@ -49,6 +49,7 @@
4949
"eslint-plugin-promise": "^3.4.0",
5050
"eslint-plugin-standard": "^3.0.1",
5151
"eslint-plugin-vue": "^4.0.0",
52+
"handlebars": "^4.1.2",
5253
"husky": "^2.4.0",
5354
"jest": "^22.0.4",
5455
"jest-serializer-vue": "^0.3.0",

0 commit comments

Comments
 (0)