From b80dfd7b9a41b03f0bc30895c300deba54df8d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 2 May 2016 13:50:51 +0200 Subject: [PATCH] Add method contentLink as deprecated for plugin API --- lib/api/deprecate.js | 20 ++++++++++++++++++++ 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 d8d6ac148..95ab93b4e 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 675f4a35b..cb91a33f5 100644 --- a/lib/api/encodeGlobal.js +++ b/lib/api/encodeGlobal.js @@ -47,15 +47,6 @@ function encodeGlobal(output) { return book.isLanguageBook(); }, - /** - 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 @@ -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');