@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
83 lines (77 loc) • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FaqStore = void 0;
const doc_structure_1 = require("../../doc-util/doc-structure");
const defaultmap_1 = require("../../../util/collections/defaultmap");
const assert_1 = require("../../../util/assert");
const FlowrFaqTopics = {
'flowr.use': '✨ Using <i>flowR</i>',
'flowr.development': '🧑💻 <i>flowR</i> Development',
'r.packages': '📦 R Packages',
'editor.configs': '⚙️ Recommended Editor Configs'
};
/**
* Manage all questions and answers by topic.
*/
class FaqStore {
faqs = new defaultmap_1.DefaultMap(() => []);
currTopic = undefined;
withTopic(topic) {
this.currTopic = topic;
return this;
}
addFaq(question, answer) {
(0, assert_1.guard)(this.currTopic !== undefined, 'Current topic is not set use withTopic first');
question = question.replace(/\*([^*]+)\*/g, '<b>$1</b>');
const store = this.faqs.get(this.currTopic);
if (store.find(([q]) => q === question)) {
throw new Error(`FAQ for question "${question}" in topic "${this.currTopic}" already exists`);
}
store.push([question, answer]);
return this;
}
printAllTopics(topicsRegex) {
const topics = Array.from(this.faqs.keys())
.filter(topic => topicsRegex.test(topic))
.sort((a, b) => a.localeCompare(b));
let output = '';
for (const topic of topics) {
const faqs = this.faqs.get(topic).sort(([q1], [q2]) => q1.localeCompare(q2));
if (faqs.length === 0) {
continue;
}
output += (0, doc_structure_1.section)(FlowrFaqTopics[topic], 3) + '\n\n';
for (const [question, answer] of faqs) {
output += qAndA(question, answer) + '\n\n';
}
}
return output;
}
toMarkdown() {
return `
${(0, doc_structure_1.collapsibleToc)({
['💮 *flowR* FAQ']: {
[FlowrFaqTopics['flowr.development']]: {},
[FlowrFaqTopics['flowr.use']]: {}
},
['🇷 R FAQ']: {
[FlowrFaqTopics['r.packages']]: {}
},
['💻 Editor FAQ']: {
[FlowrFaqTopics['editor.configs']]: {}
}
})}
${(0, doc_structure_1.section)('💮 <i>flowR</i> FAQ', 2)}
${this.printAllTopics(/^flowr.*$/)}
${(0, doc_structure_1.section)('🇷 R FAQ', 2)}
${this.printAllTopics(/^r.*$/)}
${(0, doc_structure_1.section)('💻 Editor FAQ', 2)}
${this.printAllTopics(/^editor.*$/)}
`;
}
}
exports.FaqStore = FaqStore;
function qAndA(question, answer) {
return (0, doc_structure_1.details)(question.trim(), answer.trim(), { hideIfEmpty: true });
}
//# sourceMappingURL=wiki-faq-store.js.map