summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-17 19:45:48 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-17 19:45:48 +0200
commit3e4241fc8810db9a789fa04acf0c0a61b8b46419 (patch)
tree1b89af035cf6a72a57acac08ac9b3a485d490aac
parenta5ae79604ccc068d627ab21a5f66d23279654ea1 (diff)
downloadgitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.zip
gitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.tar.gz
gitbook-3e4241fc8810db9a789fa04acf0c0a61b8b46419.tar.bz2
Implement renderInline method and missing output methods for API
-rw-r--r--docs/plugins/api.md2
-rw-r--r--lib/api/encodeGlobal.js50
-rw-r--r--lib/models/parser.js5
3 files changed, 56 insertions, 1 deletions
diff --git a/docs/plugins/api.md b/docs/plugins/api.md
index 135f196..c482ec2 100644
--- a/docs/plugins/api.md
+++ b/docs/plugins/api.md
@@ -37,7 +37,7 @@ var filepath = output.resolve('myimage.png');
var fileurl = output.toURL('mychapter/README.md');
// Write a file in the output folder
-output.write('hello.txt', 'Hello World')
+output.writeFile('hello.txt', 'Hello World')
.then(function() { ... });
// Copy a file to the output folder
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);
+ });
+ });
}
},
diff --git a/lib/models/parser.js b/lib/models/parser.js
index d28a4e2..d64542f 100644
--- a/lib/models/parser.js
+++ b/lib/models/parser.js
@@ -55,6 +55,11 @@ Parser.prototype.parsePage = function(content) {
return Promise(page(content));
};
+Parser.prototype.parseInline = function(content) {
+ var inline = this.get('inline');
+ return Promise(inline(content));
+};
+
Parser.prototype.parseLanguages = function(content) {
var langs = this.get('langs');
return Promise(langs(content));