diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-17 19:45:48 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-17 19:45:48 +0200 |
commit | 3e4241fc8810db9a789fa04acf0c0a61b8b46419 (patch) | |
tree | 1b89af035cf6a72a57acac08ac9b3a485d490aac /lib/api | |
parent | a5ae79604ccc068d627ab21a5f66d23279654ea1 (diff) | |
download | gitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.zip gitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.tar.gz gitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.tar.bz2 |
Implement renderInline method and missing output methods for API
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/encodeGlobal.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/api/encodeGlobal.js b/lib/api/encodeGlobal.js index 070da68..a366526 100644 --- a/lib/api/encodeGlobal.js +++ b/lib/api/encodeGlobal.js @@ -110,6 +110,20 @@ function encodeGlobal(output) { .get('content'); }, + /** + Render an inline text (markdown/asciidoc) + + @param {String} type + @param {String} text + @return {Promise<String>} + */ + renderInline: function(type, text) { + var parser = parsers.get(type); + + return parser.parseInline(text) + .get('content'); + }, + template: { /** Apply a templating block and returns its result @@ -158,6 +172,21 @@ function encodeGlobal(output) { }, /** + Check that a file exists. + + @param {String} fileName + @return {Promise} + */ + hasFile: function(fileName, content) { + return Promise() + .then(function() { + var filePath = PathUtils.resolveInRoot(outputFolder, fileName); + + return fs.exists(filePath); + }); + }, + + /** Write a file to the output folder, It creates the required folder @@ -175,6 +204,27 @@ function encodeGlobal(output) { return fs.writeFile(filePath, content); }); }); + }, + + /** + Copy a file to the output folder + It creates the required folder. + + @param {String} inputFile + @param {String} outputFile + @param {Buffer} content + @return {Promise} + */ + copyFile: function(inputFile, outputFile, content) { + return Promise() + .then(function() { + var outputFilePath = PathUtils.resolveInRoot(outputFolder, outputFile); + + return fs.ensureFile(outputFilePath) + .then(function() { + return fs.copy(inputFile, outputFilePath); + }); + }); } }, |