Browse Source

Add base design for plugin system

Samy Pessé 11 years ago
parent
commit
7c12972634
5 changed files with 84 additions and 2 deletions
  1. 66 0
      README.md
  2. 3 0
      book/test.css
  3. 3 0
      book/test.js
  4. 10 0
      index.js
  5. 2 2
      package.json

+ 66 - 0
README.md

@@ -4,3 +4,69 @@ GitBook Sample Plugin
 This is a sample plugin for GitBook.
 
 Install it using: ```$ npm install gitbook-plugin```
+
+## How GitBook plugin works?
+
+A plugin for GitBook is a node package that can be published on [NPM](www.npmjs.org).
+
+### package.json
+
+#### name
+
+The package name should begin with ```gitbook-```. And if your plugin is a theme, it should begin with ```gitbook-theme-```.
+
+Examples: `gitbook-googleanalytics`, `gitbook-theme-dark`
+
+#### engine
+
+The package.json should contain a `engine` field using [the standard norm](https://www.npmjs.org/doc/json.html#engines).
+
+```
+"engines": {
+    "gitbook": "*"
+}
+```
+
+For example if you want your plugin to supports only GitBook version supperior to 0.3.1: 
+
+```
+"engines": {
+    "gitbook": ">=0.3.1"
+}
+```
+
+### entry point
+
+The plugin entry point should return an object with some metadata.
+
+#### "book"
+
+Type: `Object`
+Default value: `{}`
+
+#### "book.js"
+
+Type: `Array`
+Default value: `[]`
+
+List of javascript file to add to the html pages.
+
+#### "book.css"
+
+Type: `Array`
+Default value: `[]`
+
+List of css file to add to the html pages.
+
+#### "book.templates"
+
+Type: `Object`
+Default value: `{}`
+
+Templates to override default templates, only use this option if you want to change entirely how the book is rendered.
+
+This object is a map: "name" -> "file", with names:
+
+* "site": page for a file from the `site` format
+* "page": page for the `page` format
+

+ 3 - 0
book/test.css

@@ -0,0 +1,3 @@
+body {
+    background: red;
+}

+ 3 - 0
book/test.js

@@ -0,0 +1,3 @@
+$(document).ready(function() {
+    alert("Hello World");
+});

+ 10 - 0
index.js

@@ -0,0 +1,10 @@
+module.exports = {
+    book: {
+        js: [
+            "book/test.js"
+        ],
+        css: [
+            "book/test.css"
+        ]
+    }
+};

+ 2 - 2
package.json

@@ -1,10 +1,10 @@
 {
     "name": "gitbook-plugin",
     "description": "Sample plugin for GitBook",
+    "main": "index.js",
     "version": "0.0.1",
     "engines": {
-        "gitbook": "*",
-        "node": "*"
+        "gitbook": "*"
     },
     "homepage": "https://github.com/GitbookIO/gitbook-plugin",
     "repository": {