diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-02 13:50:51 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-02 13:50:51 +0200 |
commit | b80dfd7b9a41b03f0bc30895c300deba54df8d6b (patch) | |
tree | 12135d2297f02385eb406868419e9f382180729e /lib/api | |
parent | 4c144b6ceb648053001f0a8a143cddea3d154bc3 (diff) | |
download | gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.zip gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.tar.gz gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.tar.bz2 |
Add method contentLink as deprecated for plugin API
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/deprecate.js | 20 | ||||
-rw-r--r-- | lib/api/encodeGlobal.js | 12 |
2 files changed, 23 insertions, 9 deletions
diff --git a/lib/api/deprecate.js b/lib/api/deprecate.js index d8d6ac1..95ab93b 100644 --- a/lib/api/deprecate.js +++ b/lib/api/deprecate.js @@ -1,4 +1,5 @@ var is = require('is'); +var objectPath = require('object-path'); var logged = {}; var disabled = {}; @@ -96,8 +97,27 @@ function disableDeprecation(key) { disabled[key] = true; } +/** + Deprecate a method in favor of another one + + @param {Book} book + @param {String} key + @param {Object} instance + @param {String} oldName + @param {String} newName +*/ +function deprecateRenamedMethod(book, key, instance, oldName, newName, msg) { + msg = msg || ('"' + oldName + '" is deprecated, use "' + newName + '()" instead'); + var fn = objectPath.get(instance, newName); + + instance[oldName] = deprecateMethod(book, key, function() { + return fn.apply(instance, arguments); + }. msg); +} + module.exports = { method: deprecateMethod, + renamedMethod: deprecateRenamedMethod, field: deprecateField, enable: enableDeprecation, disable: disableDeprecation diff --git a/lib/api/encodeGlobal.js b/lib/api/encodeGlobal.js index 675f4a3..cb91a33 100644 --- a/lib/api/encodeGlobal.js +++ b/lib/api/encodeGlobal.js @@ -48,15 +48,6 @@ function encodeGlobal(output) { }, /** - Same as isLanguageBook - - @deprecated - */ - isSubBook: deprecate.method(output, 'this.isSubBook', function() { - return book.isLanguageBook(); - }, '"isSubBook" is deprecated, use "isLanguageBook()" instead'), - - /** Read a file from the book @param {String} fileName @@ -141,6 +132,9 @@ function encodeGlobal(output) { // Deprecated properties + deprecate.renamedMethod(output, 'this.isSubBook', result, 'isSubBook', 'isLanguageBook'); + deprecate.renamedMethod(output, 'this.contentLink', result, 'contentLink', 'output.toURL'); + deprecate.field(output, 'this.generator', result, 'generator', output.getGenerator(), '"this.generator" property is deprecated, use "this.output.name" instead'); |