diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-04 10:59:13 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-04 10:59:13 -0700 |
commit | d475affd3bb1255d82ff810bc8ef5ac8ac2f6f3a (patch) | |
tree | 060f11df6d7ccc24e222d35cf1ce2354f0fd6b02 /lib/generate/generator_json.js | |
parent | fe3de93e06d5cc6fd757ee68013e1ec77f708018 (diff) | |
parent | 5cae311edf62e5c86edd9083a8d927730710c2f9 (diff) | |
download | gitbook-d475affd3bb1255d82ff810bc8ef5ac8ac2f6f3a.zip gitbook-d475affd3bb1255d82ff810bc8ef5ac8ac2f6f3a.tar.gz gitbook-d475affd3bb1255d82ff810bc8ef5ac8ac2f6f3a.tar.bz2 |
Merge pull request #25 from GitbookIO/feature/generators
Feature/generators
Diffstat (limited to 'lib/generate/generator_json.js')
-rw-r--r-- | lib/generate/generator_json.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/generate/generator_json.js b/lib/generate/generator_json.js new file mode 100644 index 0000000..b331bfd --- /dev/null +++ b/lib/generate/generator_json.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 |