summaryrefslogtreecommitdiffstats
path: root/lib/plugins/compatibility.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
committerSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
commit36b49c66c6b75515bc84dd678fd52121a313e8d2 (patch)
treebc7e0f703d4557869943ec7f9495cac7a5027d4f /lib/plugins/compatibility.js
parent87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff)
parent80b8e340dadc54377ff40500f86b1de631395806 (diff)
downloadgitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.zip
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.gz
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.bz2
Merge branch 'fixes'
Diffstat (limited to 'lib/plugins/compatibility.js')
-rw-r--r--lib/plugins/compatibility.js61
1 files changed, 0 insertions, 61 deletions
diff --git a/lib/plugins/compatibility.js b/lib/plugins/compatibility.js
deleted file mode 100644
index 77f4be2..0000000
--- a/lib/plugins/compatibility.js
+++ /dev/null
@@ -1,61 +0,0 @@
-var _ = require('lodash');
-var error = require('../utils/error');
-
-/*
- Return the context for a plugin.
- It tries to keep compatibilities with GitBook v2
-*/
-function pluginCtx(plugin) {
- var book = plugin.book;
- var ctx = book;
-
- return ctx;
-}
-
-/*
- Call a function "fn" with a context of page similar to the one in GitBook v2
-
- @params {Page}
- @returns {String|undefined} new content of the page
-*/
-function pageHook(page, fn) {
- // Get page context
- var ctx = page.getContext().page;
-
- // Add other informations
- ctx.type = page.type;
- ctx.rawPath = page.rawPath;
- ctx.path = page.path;
-
- // Deprecate sections
- error.deprecateField(ctx, 'sections', [
- { content: ctx.content, type: 'normal' }
- ], '"sections" property is deprecated, use page.content instead');
-
- // Keep reference of original content for compatibility
- var originalContent = ctx.content;
-
- return fn(ctx)
- .then(function(result) {
- // No returned value
- // Existing content will be used
- if (!result) return undefined;
-
- // GitBook 3
- // Use returned page.content if different from original content
- if (result.content != originalContent) {
- return result.content;
- }
-
- // GitBook 2 compatibility
- // Finally, use page.sections
- if (result.sections) {
- return _.pluck(result.sections, 'content').join('\n');
- }
- });
-}
-
-module.exports = {
- pluginCtx: pluginCtx,
- pageHook: pageHook
-};