diff options
Diffstat (limited to 'lib/generate/json/index.js')
-rw-r--r-- | lib/generate/json/index.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/generate/json/index.js b/lib/generate/json/index.js new file mode 100644 index 0000000..f301a7e --- /dev/null +++ b/lib/generate/json/index.js @@ -0,0 +1,47 @@ +var util = require("util"); +var path = require("path"); +var Q = require("q"); + +var fs = require("../fs"); +var parse = require("../../parse"); +var BaseGenerator = require("../generator"); + + +var Generator = function() { + BaseGenerator.apply(this, arguments); +}; +util.inherits(Generator, BaseGenerator); + +Generator.prototype.transferFile = function(input) { + // ignore +}; + +Generator.prototype.convertFile = function(content, input) { + var that = this; + var json = { + progress: parse.progress(this.options.navigation, input) + }; + + return Q() + .then(function() { + return parse.page(content, { + repo: that.options.githubId, + dir: path.dirname(input) || '/' + }); + }) + .then(function(sections) { + json.sections = sections; + }) + .then(function() { + return fs.writeFile( + path.join(that.options.output, input.replace(".md", ".json")), + JSON.stringify(json, null, 4) + ); + }); +}; + +Generator.prototype.finish = function() { + // ignore +}; + +module.exports = Generator;
\ No newline at end of file |