diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-04-27 10:38:54 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-04-27 10:38:54 +0200 |
commit | b05eb8440b59db6d39ae06712ddda5651786e00a (patch) | |
tree | 1354043c55fccf0e114ec84307c23afa59ff340d /lib/api | |
parent | f4de7748f596a060e9a59df0447315b59d7c47de (diff) | |
download | gitbook-b05eb8440b59db6d39ae06712ddda5651786e00a.zip gitbook-b05eb8440b59db6d39ae06712ddda5651786e00a.tar.gz gitbook-b05eb8440b59db6d39ae06712ddda5651786e00a.tar.bz2 |
Don;t log deprecation warning for own logic
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/decodeConfig.js | 4 | ||||
-rw-r--r-- | lib/api/decodePage.js | 11 | ||||
-rw-r--r-- | lib/api/deprecate.js | 28 | ||||
-rw-r--r-- | lib/api/encodePage.js | 2 |
4 files changed, 38 insertions, 7 deletions
diff --git a/lib/api/decodeConfig.js b/lib/api/decodeConfig.js index 886ba45..351ed05 100644 --- a/lib/api/decodeConfig.js +++ b/lib/api/decodeConfig.js @@ -9,6 +9,10 @@ var Config = require('../models/config'); */ function decodeGlobal(config, result) { var values = result.values; + + delete values.generator; + delete values.output; + return Config.updateValues(config, values); } diff --git a/lib/api/decodePage.js b/lib/api/decodePage.js index e0b7d1e..c85dd1b 100644 --- a/lib/api/decodePage.js +++ b/lib/api/decodePage.js @@ -1,3 +1,4 @@ +var deprecate = require('./deprecate'); /** Decode changes from a JS API to a page object. @@ -17,22 +18,26 @@ function decodePage(output, page, result) { return page; } + deprecate.disable('page.sections'); + // GitBook 3 // Use returned page.content if different from original content if (result.content != originalContent) { - return page.set('content', result.content); + page = page.set('content', result.content); } // GitBook 2 compatibility // Finally, use page.sections - if (result.sections) { - return page.set('content', + else if (result.sections) { + page = page.set('content', result.sections.map(function(section) { return section.content; }).join('\n') ); } + deprecate.enable('page.sections'); + return page; } diff --git a/lib/api/deprecate.js b/lib/api/deprecate.js index b890777..73ca8be 100644 --- a/lib/api/deprecate.js +++ b/lib/api/deprecate.js @@ -1,4 +1,5 @@ var logged = {}; +var disabled = {}; /** Log a deprecated notice @@ -8,7 +9,7 @@ var logged = {}; @param {String} message */ function logNotice(book, key, message) { - if (logged[key]) return; + if (logged[key] || disabled[key]) return; logged[key] = true; @@ -57,11 +58,32 @@ function deprecateField(book, key, instance, property, value, msg) { Object.defineProperty(instance, property, { get: getter, set: setter, - enumerable: true + enumerable: true, + configurable: true }); } +/** + Enable a deprecation + + @param {String} key: unique identitifer +*/ +function enableDeprecation(key) { + disabled[key] = false; +} + +/** + Disable a deprecation + + @param {String} key: unique identitifer +*/ +function disableDeprecation(key) { + disabled[key] = true; +} + module.exports = { method: deprecateMethod, - field: deprecateField + field: deprecateField, + enable: enableDeprecation, + disable: disableDeprecation }; diff --git a/lib/api/encodePage.js b/lib/api/encodePage.js index 98d7409..1f3a01b 100644 --- a/lib/api/encodePage.js +++ b/lib/api/encodePage.js @@ -21,7 +21,7 @@ function encodePage(output, page) { result.path = file.getPath(); result.rawPath = fs.resolve(result.path); - deprecate.field(output, 'page.section', result, 'sections', [ + deprecate.field(output, 'page.sections', result, 'sections', [ { content: result.content, type: 'normal' |