summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-22 09:54:24 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-22 09:54:24 +0200
commit0b1888e184d3f995c3130daf794416ad0a4312bc (patch)
treeb22af323c65ad0e4d458ff6ab85bad00b5a39ba8 /docs
parent2257e42299f28f2a276bf2febd7f5d00e3931c08 (diff)
downloadgitbook-0b1888e184d3f995c3130daf794416ad0a4312bc.zip
gitbook-0b1888e184d3f995c3130daf794416ad0a4312bc.tar.gz
gitbook-0b1888e184d3f995c3130daf794416ad0a4312bc.tar.bz2
First working version in the browser
Diffstat (limited to 'docs')
-rw-r--r--docs/api/README.md3
-rw-r--r--docs/api/node.md97
2 files changed, 100 insertions, 0 deletions
diff --git a/docs/api/README.md b/docs/api/README.md
new file mode 100644
index 0000000..4349fd4
--- /dev/null
+++ b/docs/api/README.md
@@ -0,0 +1,3 @@
+# Plugin Architecture
+
+A GitBook plugin is a NPM package that follow a defined convention.
diff --git a/docs/api/node.md b/docs/api/node.md
new file mode 100644
index 0000000..99bf1a7
--- /dev/null
+++ b/docs/api/node.md
@@ -0,0 +1,97 @@
+# Context and APIs
+
+GitBooks provides different Node APIs and contexts to plugins. These APIs can vary according to the GitBook version being used, your plugin should specify the `engines.gitbook` field in `package.json` accordingly.
+
+#### Book instance
+
+The `Book` interface is the central point of GitBook, it centralize all access read methods.
+
+```js
+// Read configuration from book.json
+var value = book.config.get('title', 'Default Value');
+
+// Resolve a filename to an absolute path
+var filepath = book.resolve('README.md');
+
+// Render an inline markup string
+book.renderInline('markdown', 'This is **Markdown**')
+ .then(function(str) { ... })
+
+// Render a markup string (block mode)
+book.renderBlock('markdown', '* This is **Markdown**')
+ .then(function(str) { ... })
+```
+
+#### Output instance
+
+The `Output` class represent the output/write process.
+
+```js
+// Return root folder for the output
+var root = output.root();
+
+// Resolve a file in the output folder
+var filepath = output.resolve('myimage.png');
+
+// Convert a filename to an URL (returns a path to an html file)
+var fileurl = output.toURL('mychapter/README.md');
+
+// Write a file in the output folder
+output.writeFile('hello.txt', 'Hello World')
+ .then(function() { ... });
+
+// Copy a file to the output folder
+output.copyFile('./myfile.jpg', 'cover.jpg')
+ .then(function() { ... });
+
+// Verify that a file exists
+output.hasFile('hello.txt')
+ .then(function(exists) { ... });
+```
+
+#### Page instance
+
+A page instance represent the current parsed page.
+
+```js
+// Title of the page (from SUMMARY)
+page.title
+
+// Content of the page (Markdown/Asciidoc/HTML according to the stage)
+page.content
+
+// Relative path in the book
+page.path
+
+// Absolute path to the file
+page.rawPath
+
+// Type of parser used for this file
+page.type ('markdown' or 'asciidoc')
+```
+
+#### Context for Blocks and Filters
+
+Blocks and filters have access to the same context, this context is bind to the template engine execution:
+
+```js
+{
+ // Current templating syntax
+ "ctx": {
+ // For example, after a {% set message = "hello" %}
+ "message": "hello"
+ },
+
+ // Book instance
+ "book" <Book>,
+
+ // Output instance
+ "output": <Output>
+}
+```
+
+For example a filter or block function can access the current book using: `this.book`.
+
+#### Context for Hooks
+
+Hooks only have access to the `<Book>` instance using `this.book`.