|
|
@@ -21,6 +21,7 @@ let keyDefs = {};
|
|
|
let pathToXref = {};
|
|
|
let knownTitles = {};
|
|
|
let xrefs = {};
|
|
|
+let conRefs = {};
|
|
|
|
|
|
let handleChildNodes = (x, path, body) => {
|
|
|
x.childNodes().forEach(y => {
|
|
|
@@ -65,17 +66,29 @@ let handleElement = (x, path, body) => {
|
|
|
} else {
|
|
|
body.push(x.attr('keyref').value())
|
|
|
}
|
|
|
+ } else if (x.attr('conref') && x.attr('conref').value().indexOf('impala_common.xml') !== -1) {
|
|
|
+ var id = x.attr('conref').value().replace(/^.*common\//, '');
|
|
|
+ if (conRefs[id]) {
|
|
|
+ handleElement(conRefs[id], path, body);
|
|
|
+ } else {
|
|
|
+ console.log('concept ref not found with id: ' + id);
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
switch (x.name()) {
|
|
|
case 'title': { wrapHtmlElement(x, path, body, 'h4'); break; }
|
|
|
- case 'p': { wrapHtmlElement(x, path, body, 'p'); break; }
|
|
|
+ case 'p': {
|
|
|
+ wrapHtmlElement(x, path, body, 'p');
|
|
|
+ break;
|
|
|
+ }
|
|
|
case 'concept': {
|
|
|
- wrapHtmlElement(x, path, body, 'div');
|
|
|
- if (x.attr('id') && x.get('title')) {
|
|
|
- var titleParts = [];
|
|
|
- handleElement(x.get('title'), path, titleParts);
|
|
|
- knownTitles[path.substring(path.indexOf('topics/')) + '#' + x.attr('id').value()] = titleParts.join('');
|
|
|
+ if (!x.attr('audience') || x.attr('audience').value() !== 'hidden') {
|
|
|
+ wrapHtmlElement(x, path, body, 'div');
|
|
|
+ if (x.attr('id') && x.get('title')) {
|
|
|
+ var titleParts = [];
|
|
|
+ handleElement(x.get('title'), path, titleParts);
|
|
|
+ knownTitles[path.substring(path.indexOf('topics/')) + '#' + x.attr('id').value()] = titleParts.join('');
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -106,16 +119,19 @@ let handleElement = (x, path, body) => {
|
|
|
case 'filepath':
|
|
|
case 'term': { wrapHtmlElement(x, path, body, 'span', 'sql-docs-variable'); break; }
|
|
|
case 'note': { wrapHtmlElement(x, path, body, 'div', 'sql-docs-note'); break; }
|
|
|
- case 'b': { wrapHtmlElement(x, path, body, 'b', 'sql-docs-variable'); break; }
|
|
|
- case 'q': { wrapHtmlElement(x, path, body, 'q', 'sql-docs-variable'); break; }
|
|
|
- case 'i': { wrapHtmlElement(x, path, body, 'i', 'sql-docs-variable'); break; }
|
|
|
- case 'sup': { wrapHtmlElement(x, path, body, 'sup', 'sql-docs-variable'); break; }
|
|
|
- case 'ul': { wrapHtmlElement(x, path, body, 'ul', 'sql-docs-variable'); break; }
|
|
|
- case 'li': { wrapHtmlElement(x, path, body, 'li', 'sql-docs-variable'); break; }
|
|
|
+ case 'b': { wrapHtmlElement(x, path, body, 'b'); break; }
|
|
|
+ case 'q': { wrapHtmlElement(x, path, body, 'q'); break; }
|
|
|
+ case 'i': { wrapHtmlElement(x, path, body, 'i'); break; }
|
|
|
+ case 'sup': { wrapHtmlElement(x, path, body, 'sup'); break; }
|
|
|
+ case 'ul': { wrapHtmlElement(x, path, body, 'ul'); break; }
|
|
|
+ case 'li': { wrapHtmlElement(x, path, body, 'li'); break; }
|
|
|
case 'indexterm':
|
|
|
case 'metadata':
|
|
|
case 'fig':
|
|
|
case 'prolog':
|
|
|
+ case 'titlealts':
|
|
|
+ case 'uicontrol':
|
|
|
+ case 'table':
|
|
|
case 'navtitle': break;
|
|
|
default: console.log('Could not process element of type: ' + x.name() + ' in ' + path);
|
|
|
}
|
|
|
@@ -136,7 +152,7 @@ let parseDml = (path) => {
|
|
|
}
|
|
|
xmlDoc.get('//title').remove();
|
|
|
xmlDoc.childNodes().forEach(x => {
|
|
|
- handleChildNodes(x, path, body);
|
|
|
+ handleElement(x, path, body);
|
|
|
});
|
|
|
resolve({ title: titleParts.join(''), body: body});
|
|
|
} catch (err) {
|
|
|
@@ -172,7 +188,7 @@ class Topic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-fs.readFile('../Impala/docs/impala_keydefs.ditamap', 'utf8', (err, keyDefRaw) => {
|
|
|
+ fs.readFile('../Impala/docs/impala_keydefs.ditamap', 'utf8', (err, keyDefRaw) => {
|
|
|
if (err) {
|
|
|
console.log('Could not find the Impala docs! (../Impala/docs/impala_keydefs.ditamap)');
|
|
|
console.log('Make sure you have Impala checked out in an "Impala" folder next to the hue folder');
|
|
|
@@ -180,110 +196,126 @@ fs.readFile('../Impala/docs/impala_keydefs.ditamap', 'utf8', (err, keyDefRaw) =>
|
|
|
}
|
|
|
|
|
|
libxml.parseXmlString(keyDefRaw).get('//map').childNodes().forEach(x => {
|
|
|
- if (x.name() === 'keydef' && x.attr('keys')) {
|
|
|
- let valNode = x.get('topicmeta/keywords/keyword');
|
|
|
- if (valNode) {
|
|
|
- keyDefs[x.attr('keys').value()] = valNode.text();
|
|
|
- } else if (x.attr('href')) {
|
|
|
- xrefs[x.attr('keys')] = {
|
|
|
- ref: x.attr('href').value(),
|
|
|
- parsed: false,
|
|
|
- external: x.attr('scope') && x.attr('scope').value() === 'external'
|
|
|
- };
|
|
|
- pathToXref[x.attr('href').value()] = xrefs[x.attr('keys')];
|
|
|
- }
|
|
|
- }
|
|
|
+ if (x.name() === 'keydef' && x.attr('keys')) {
|
|
|
+ let valNode = x.get('topicmeta/keywords/keyword');
|
|
|
+ if (valNode) {
|
|
|
+ keyDefs[x.attr('keys').value()] = valNode.text();
|
|
|
+ } else if (x.attr('href')) {
|
|
|
+ xrefs[x.attr('keys')] = {
|
|
|
+ ref: x.attr('href').value(),
|
|
|
+ parsed: false,
|
|
|
+ external: x.attr('scope') && x.attr('scope').value() === 'external'
|
|
|
+ };
|
|
|
+ pathToXref[x.attr('href').value()] = xrefs[x.attr('keys')];
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
let stringifyTopic = (topic, prefix) => {
|
|
|
- let result = prefix + '{\n' + prefix + ' id: \'' + topic.ref + '\',\n' + prefix + ' title: \'' + topic.title + '\',\n' + prefix + ' weight: 1,\n' + prefix + ' bodyMatch: ko.observable(),\n' + prefix + ' open: ko.observable(false),\n' + prefix +' titleMatch: ko.observable()';
|
|
|
+ let result = prefix + '{\n' + prefix + ' id: \'' + topic.ref + '\',\n' + prefix + ' title: \'' + topic.title + '\',\n' + prefix + ' weight: 1,\n' + prefix + ' bodyMatch: ko.observable(),\n' + prefix + ' open: ko.observable(false),\n' + prefix +' titleMatch: ko.observable()';
|
|
|
|
|
|
- if (topic.body.length) {
|
|
|
- var bodyString = '';
|
|
|
- topic.body.forEach(function (bodyElement) {
|
|
|
- if (typeof bodyElement === 'string') {
|
|
|
- bodyString += bodyElement;
|
|
|
- } else if (bodyElement.xrefNode) {
|
|
|
- if (bodyElement.xrefNode.attr('href')) {
|
|
|
- if (bodyElement.xrefNode.attr('scope') && bodyElement.xrefNode.attr('scope').value() === 'external') {
|
|
|
- bodyString += '<a target="_blank" href="' + bodyElement.xrefNode.attr('href').value() + '">' + bodyElement.xrefNode.text() + '</a>'
|
|
|
- } else {
|
|
|
- let href = bodyElement.xrefNode.attr('href').value();
|
|
|
- if (href.indexOf('#') === 0) {
|
|
|
- href = bodyElement.path.substring(bodyElement.path.indexOf('topics/')) + href;
|
|
|
- } else if (href.indexOf('topics/') !== -1) {
|
|
|
- href = href.substring(href.indexOf('topics')); // clean up [..]/topic/ etc.
|
|
|
- } else {
|
|
|
- href = 'topics/' + href;
|
|
|
- }
|
|
|
- var split = href.split('#');
|
|
|
+ if (topic.body.length) {
|
|
|
+ var bodyString = '';
|
|
|
+ topic.body.forEach(function (bodyElement) {
|
|
|
+ if (typeof bodyElement === 'string') {
|
|
|
+ bodyString += bodyElement;
|
|
|
+ } else if (bodyElement.xrefNode) {
|
|
|
+ if (bodyElement.xrefNode.attr('href')) {
|
|
|
+ if (bodyElement.xrefNode.attr('scope') && bodyElement.xrefNode.attr('scope').value() === 'external') {
|
|
|
+ bodyString += '<a target="_blank" href="' + bodyElement.xrefNode.attr('href').value() + '">' + bodyElement.xrefNode.text() + '</a>'
|
|
|
+ } else {
|
|
|
+ let href = bodyElement.xrefNode.attr('href').value();
|
|
|
+ if (href.indexOf('#') === 0) {
|
|
|
+ href = bodyElement.path.substring(bodyElement.path.indexOf('topics/')) + href;
|
|
|
+ } else if (href.indexOf('topics/') !== -1) {
|
|
|
+ href = href.substring(href.indexOf('topics')); // clean up [..]/topic/ etc.
|
|
|
+ } else {
|
|
|
+ href = 'topics/' + href;
|
|
|
+ }
|
|
|
+ var split = href.split('#');
|
|
|
|
|
|
- var unknown = false;
|
|
|
- let title = href;
|
|
|
- if (knownTitles[href]) {
|
|
|
- title = bodyElement.xrefNode.text() || knownTitles[href];
|
|
|
- } else if (knownTitles[split[0]]) {
|
|
|
- title = bodyElement.xrefNode.text() || knownTitles[split[0]];
|
|
|
- } else if (bodyElement.xrefNode.text()) {
|
|
|
- unknown = true;
|
|
|
- title = bodyElement.xrefNode.text();
|
|
|
- } else if (split[1]) {
|
|
|
- unknown = true;
|
|
|
- title = split[1].replace(/_/g, ' ');
|
|
|
- } else {
|
|
|
- unknown = true;
|
|
|
- title = href.replace('topics/', '').replace('.xml', '').replace(/_/g, ' ');
|
|
|
- }
|
|
|
+ var unknown = false;
|
|
|
+ let title = href;
|
|
|
+ if (knownTitles[href]) {
|
|
|
+ title = bodyElement.xrefNode.text() || knownTitles[href];
|
|
|
+ } else if (knownTitles[split[0]]) {
|
|
|
+ title = bodyElement.xrefNode.text() || knownTitles[split[0]];
|
|
|
+ } else if (bodyElement.xrefNode.text()) {
|
|
|
+ unknown = true;
|
|
|
+ title = bodyElement.xrefNode.text();
|
|
|
+ } else if (split[1]) {
|
|
|
+ unknown = true;
|
|
|
+ title = split[1].replace(/_/g, ' ');
|
|
|
+ } else {
|
|
|
+ unknown = true;
|
|
|
+ title = href.replace('topics/', '').replace('.xml', '').replace(/_/g, ' ');
|
|
|
+ }
|
|
|
|
|
|
- if (unknown) {
|
|
|
- bodyString += '<span>"' + title + '"</span>'; // Unknown = not parsed reference as some docs are excluded
|
|
|
- } else {
|
|
|
- bodyString += '<a href="javascript: void(0);" class="lang-ref-link" data-target="' + href + '">' + title + '</a>';
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (unknown) {
|
|
|
+ bodyString += '<span>' + title + '</span>'; // Unknown = not parsed reference as some docs are excluded
|
|
|
+ } else {
|
|
|
+ bodyString += '<a href="javascript: void(0);" class="lang-ref-link" data-target="' + href + '">' + title + '</a>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ result += ',\n' + prefix + ' body: \'' + bodyString.replace(/([^\\])\\([^\\])/g, '$1\\\\$2').replace(/'/g, '\\\'').replace(/\n/g, '\' + \n' + prefix + ' \'') + '\''
|
|
|
+ }
|
|
|
+ if (topic.children.length) {
|
|
|
+ result += ',\n' + prefix + ' children: [\n';
|
|
|
+ let stringifiedChildren = [];
|
|
|
+ topic.children.forEach(child => {
|
|
|
+ stringifiedChildren.push(stringifyTopic(child, prefix + ' '))
|
|
|
+ });
|
|
|
+ result += stringifiedChildren.join(',\n');
|
|
|
+ result += prefix + ']';
|
|
|
+ } else {
|
|
|
+ result += ',\n' + prefix + ' children: []\n';
|
|
|
+ }
|
|
|
+ result += prefix + '}';
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+
|
|
|
+ fs.readFile('../Impala/docs/shared/impala_common.xml', 'utf-8', (err, commonRaw) => {
|
|
|
+
|
|
|
+ let handleCommonChildren = children => {
|
|
|
+ children.forEach(child => {
|
|
|
+ if (child.attr('id')) {
|
|
|
+ conRefs[child.attr('id').value()] = child;
|
|
|
}
|
|
|
- });
|
|
|
- result += ',\n' + prefix + ' body: \'' + bodyString.replace(/([^\\])\\([^\\])/g, '$1\\\\$2').replace(/'/g, '\\\'').replace(/\n/g, '\' + \n' + prefix + ' \'') + '\''
|
|
|
- }
|
|
|
- if (topic.children.length) {
|
|
|
- result += ',\n' + prefix + ' children: [\n';
|
|
|
- let stringifiedChildren = [];
|
|
|
- topic.children.forEach(child => {
|
|
|
- stringifiedChildren.push(stringifyTopic(child, prefix + ' '))
|
|
|
- });
|
|
|
- result += stringifiedChildren.join(',\n');
|
|
|
- result += prefix + ']';
|
|
|
- } else {
|
|
|
- result += ',\n' + prefix + ' children: []\n';
|
|
|
- }
|
|
|
- result += prefix + '}';
|
|
|
- return result;
|
|
|
- };
|
|
|
+ if (child.childNodes().length) {
|
|
|
+ handleCommonChildren(child.childNodes());
|
|
|
+ }
|
|
|
+ })
|
|
|
+ };
|
|
|
|
|
|
- fs.readFile('../Impala/docs/impala_sqlref.ditamap', 'utf8', (err, mapRaw) => {
|
|
|
- let topics = [];
|
|
|
- let promises = [];
|
|
|
+ handleCommonChildren(libxml.parseXmlString(commonRaw).get('//conbody').childNodes());
|
|
|
|
|
|
- libxml.parseXmlString(mapRaw).get('//map').childNodes().forEach(x => {
|
|
|
- if (x.name() === 'topicref' && x.attr('href').value() !== 'topics/impala_functions.xml') {
|
|
|
- topics.push(new Topic(x.attr('href').value(), x, promises));
|
|
|
- }
|
|
|
- });
|
|
|
+ fs.readFile('../Impala/docs/impala_sqlref.ditamap', 'utf8', (err, mapRaw) => {
|
|
|
+ let topics = [];
|
|
|
+ let promises = [];
|
|
|
|
|
|
- Promise.all(promises).then(() => {
|
|
|
- fs.readFile('tools/jison/license.txt', 'utf-8', (err, licenseHeader) => {
|
|
|
- let result = licenseHeader + '\n\n\n// NOTE: This is a generated file!\n// Run \'node tools/sql-docs/impalaExtractor.js\' to generate.\n\n\nvar impalaLangRefTopics = [\n';
|
|
|
- let stringifiedTopics = [];
|
|
|
- topics.forEach(topic => {
|
|
|
- stringifiedTopics.push(stringifyTopic(topic, ''));
|
|
|
- });
|
|
|
- result += stringifiedTopics.join(',\n');
|
|
|
- result += '\n];';
|
|
|
- fs.writeFile('desktop/core/src/desktop/static/desktop/js/sqlImpalaLangRef.js', result, () => {
|
|
|
- console.log('desktop/core/src/desktop/static/desktop/js/sqlImpalaLangRef.js updated!');
|
|
|
+ libxml.parseXmlString(mapRaw).get('//map').childNodes().forEach(x => {
|
|
|
+ if (x.name() === 'topicref' && x.attr('href').value() !== 'topics/impala_functions.xml') {
|
|
|
+ topics.push(new Topic(x.attr('href').value(), x, promises));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Promise.all(promises).then(() => {
|
|
|
+ fs.readFile('tools/jison/license.txt', 'utf-8', (err, licenseHeader) => {
|
|
|
+ let result = licenseHeader + '\n\n\n// NOTE: This is a generated file!\n// Run \'node tools/sql-docs/impalaExtractor.js\' to generate.\n\n\nvar impalaLangRefTopics = [\n';
|
|
|
+ let stringifiedTopics = [];
|
|
|
+ topics.forEach(topic => {
|
|
|
+ stringifiedTopics.push(stringifyTopic(topic, ''));
|
|
|
+ });
|
|
|
+ result += stringifiedTopics.join(',\n');
|
|
|
+ result += '\n];';
|
|
|
+ fs.writeFile('desktop/core/src/desktop/static/desktop/js/sqlImpalaLangRef.js', result, () => {
|
|
|
+ console.log('desktop/core/src/desktop/static/desktop/js/sqlImpalaLangRef.js updated!');
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ })
|
|
|
});
|