-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
44 lines (38 loc) · 1.39 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
const fs = require('fs');
const path = require('path');
const elementParser = require('./parser/api_example');
const schemas = {
'json': require('./schema/json'),
'jsonschema': require('./schema/jsonschema'),
'xml': require('./schema/xml')
};
let app = {};
module.exports = {
init: function(_app) {
app = _app;
//app.addHook('parser-find-element-apiexample', parserExampleElement);
app.addHook('parser-find-elements', parserExampleElements, 201);
}
};
// Doesn't work
function parserExampleElement(elements, element, block, filename) {
const values = elementParser.parse(element.content, element.source);
app.log.debug('apiexample.path',values.path);
if (schemas[values.schema]) {
const data = fs.readFileSync( path.join(path.dirname(filename), values.path), 'utf8').toString();
element = schemas[values.schema](data, values.element, values.title);
}
return element;
}
function parserExampleElements(elements, element, block, filename) {
if ( element.name !== 'apiexample' ) { return elements; }
elements.pop();
const values = elementParser.parse(element.content, element.source);
if (values && schemas[values.schema]) {
app.log.debug('apiexample.path',values.path);
const data = fs.readFileSync( path.join(path.dirname(filename), values.path), 'utf8').toString();
element = schemas[values.schema](data, values.element, values.title);
}
elements.push(element);
return elements;
}