-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-mustache.js
66 lines (62 loc) · 1.81 KB
/
process-mustache.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
var path = require("path");
/**
* @parent bit-docs-process-mustache/modules
* @module {function} bit-docs-process-mustache/process-mustache
*
* @signature `processMustache(filename, source, docMap, siteConfig, addToDocMap)`
*
* Processes a `.mustache` file and adds it as a template to the
* [bit-docs/types/docMap].
*
* @param {String} filename The filename with its extension.
*
* @param {String} source A files source.
*
* @param {bit-docs/types/docMap} docMap A map of the name of each
* [bit-docs/types/docObject] to the [bit-docs/types/docObject].
*
* @param {{}} [siteConfig] An siteConfig object.
*
* @param {function} addToDocMap A callback function that adds passed
* [bit-docs/types/docObject] to [bit-docs/types/docMap].
*
* @body
*/
module.exports = function(filename, source, docMap, siteConfig, addToDocMap) {
if (isMustache(filename)) {
addToDocMap({
body: source,
type: "template",
name: getDocMapName(filename)
});
}
};
/**
* @function bit-docs-process-mustache/process-mustache.isMustache isMustache
*
* Whether the filename has mustache or handlebars extension
*
* @signature `isMustache(filename)`
*
* @param {String} filename The filename with its extension
*
* @return {Boolean} True is the filename ends with `.mustache` or `.handlebars`
*/
function isMustache(filename) {
var ext = path.extname(filename);
return (ext === ".mustache" || ext === ".handlebars");
}
/**
* @function bit-docs-process-mustache/process-mustache.getDocMapName getDocMapName
*
* Returns the filename without the extension
*
* @signature `getDocMapName(filename)`
*
* @param {String} filename The filename with its extension
*
* @return {String} The actual filename
*/
function getDocMapName(filename) {
return path.basename(filename, path.extname(filename));
}