-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
77 lines (70 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const sassdocAnnotations = require('sassdoc/dist/annotation/annotations');
const access = require('./lib/annotations/access');
const colors = require('./lib/annotations/colors');
const example = require('./lib/annotations/example');
const font = require('./lib/annotations/font');
const icons = require('./lib/annotations/icons');
const name = require('./lib/annotations/name');
const ratios = require('./lib/annotations/ratios');
const sizes = require('./lib/annotations/sizes');
const prepareContext = require('./lib/prepareContext');
const { renderHerman } = require('./lib/renderHerman');
const { isProse } = require('./lib/utils/prose');
/**
* Actual theme function. It takes the destination directory `dest`,
* and the context variables `ctx`.
*/
const herman = (dest, ctx) =>
prepareContext(ctx).then((preparedContext) =>
renderHerman(dest, preparedContext),
);
// Because Herman handles "prose" blocks differently than SassDoc,
// autofilled annotations are often incorrect when used with Herman.
// So we iterate through the core annotations that have autofill logic,
// and override that to abort if the item will be treated as "prose" by Herman.
// See: https://www.oddbird.net/herman/docs/demo_test-sassdoc#extra-commentary
const customAnnotationNames = [
'access',
'colors',
'example',
'font',
'icons',
'name',
'ratios',
'sizes',
];
const annotations = sassdocAnnotations
.filter((a) => {
const obj = a({ logger: console });
return (
!customAnnotationNames.includes(obj.name) &&
Object.prototype.hasOwnProperty.call(obj, 'autofill')
);
})
.map((a) => () => {
const obj = a({ logger: console });
return {
...obj,
autofill: (item) => {
if (isProse(item)) {
return undefined;
}
return obj.autofill(item);
},
};
});
herman.annotations = [
...annotations,
access,
colors,
example,
font,
icons,
name,
ratios,
sizes,
];
// make sure sassdoc will preserve comments not attached to Sass
herman.includeUnknownContexts = true;
module.exports = herman;