diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-08 10:33:45 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-08 10:33:45 +0200 |
commit | 54956de59f1a3a5796b4a3665d36c08cba91bf4d (patch) | |
tree | c24b86d40950fa47b94dd9d6746e21c4fc5515e9 /lib/api/encodeSummary.js | |
parent | 2cbd30d1f22ab2c886c05b8e33631b9f1f175160 (diff) | |
download | gitbook-54956de59f1a3a5796b4a3665d36c08cba91bf4d.zip gitbook-54956de59f1a3a5796b4a3665d36c08cba91bf4d.tar.gz gitbook-54956de59f1a3a5796b4a3665d36c08cba91bf4d.tar.bz2 |
Start API for plugins to access the summary
Diffstat (limited to 'lib/api/encodeSummary.js')
-rw-r--r-- | lib/api/encodeSummary.js | 40 |
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; |