summaryrefslogtreecommitdiffstats
path: root/lib/api/encodeSummary.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/encodeSummary.js')
-rw-r--r--lib/api/encodeSummary.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/api/encodeSummary.js b/lib/api/encodeSummary.js
new file mode 100644
index 0000000..2bb8d11
--- /dev/null
+++ b/lib/api/encodeSummary.js
@@ -0,0 +1,40 @@
+var encodeSummaryArticle = require('../json/encodeSummaryArticle');
+
+/**
+ Encode summary to provide an API to plugin
+
+ @param {Output} output
+ @param {Config} config
+ @return {Object}
+*/
+function encodeSummary(output, summary) {
+ var result = {
+ /**
+ Iterate over the summary
+
+ @param {Function} iter
+ */
+ walk: function (iter) {
+ summary.getArticle(function(article) {
+ var jsonArticle = encodeSummaryArticle(article, false);
+
+ return iter(jsonArticle);
+ });
+ },
+
+ /**
+ Get an article by its level
+
+ @param {String} level
+ @return {Object}
+ */
+ getArticleByLevel: function(level) {
+ var article = summary.getByLevel(level);
+ return (article? encodeSummaryArticle(article) : undefined);
+ }
+ };
+
+ return result;
+}
+
+module.exports = encodeSummary;