From 42dedfcaccf99cdcd95c26608c23cc2a543f3bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 15 Oct 2014 13:54:21 +0200 Subject: [PATCH] Move `convertText` to `typeConverter` Create a new module `lib/type-converter.js`. Move `routeHelper.convertText` to this new module. --- lib/class-helper.js | 4 ++-- lib/route-helper.js | 19 ++++--------------- lib/type-converter.js | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 lib/type-converter.js diff --git a/lib/class-helper.js b/lib/class-helper.js index 1e9c128..c03cb1b 100644 --- a/lib/class-helper.js +++ b/lib/class-helper.js @@ -4,7 +4,7 @@ * Module dependencies. */ var modelHelper = require('./model-helper'); -var routeHelper = require('./route-helper'); +var typeConverter = require('./type-converter'); var urlJoin = require('./url-join'); /** @@ -47,7 +47,7 @@ var classHelper = module.exports = { return { path: aClass.http.path, - description: routeHelper.convertText(description) + description: typeConverter.convertText(description) }; } }; diff --git a/lib/route-helper.js b/lib/route-helper.js index f52ed4c..add9775 100644 --- a/lib/route-helper.js +++ b/lib/route-helper.js @@ -8,6 +8,7 @@ var debug = require('debug')('loopback:explorer:routeHelpers'); var _cloneDeep = require('lodash.clonedeep'); var translateDataTypeKeys = require('./translate-data-type-keys'); var modelHelper = require('./model-helper'); +var typeConverter = require('./type-converter'); /** * Export the routeHelper singleton. @@ -142,8 +143,8 @@ var routeHelper = module.exports = { parameters: accepts, // TODO(schoon) - We don't have descriptions for this yet. responseMessages: [], - summary: routeHelper.convertText(route.description), - notes: routeHelper.convertText(route.notes), + summary: typeConverter.convertText(route.description), + notes: typeConverter.convertText(route.notes), deprecated: route.deprecated })] }; @@ -200,7 +201,7 @@ var routeHelper = module.exports = { var out = { paramType: paramType || type, name: name, - description: routeHelper.convertText(accepts.description), + description: typeConverter.convertText(accepts.description), type: accepts.type, required: !!accepts.required, defaultValue: accepts.defaultValue, @@ -239,18 +240,6 @@ var routeHelper = module.exports = { obj[key] = typeDesc[key]; }); return obj; - }, - - /** - * Convert a text value that can be expressed either as a string or - * as an array of strings. - * @param {string|Array} value - * @returns {string} - */ - convertText: function(value) { - if (Array.isArray(value)) - return value.join('\n'); - return value; } }; diff --git a/lib/type-converter.js b/lib/type-converter.js new file mode 100644 index 0000000..c7eb686 --- /dev/null +++ b/lib/type-converter.js @@ -0,0 +1,14 @@ +var typeConverter = module.exports = { + + /** + * Convert a text value that can be expressed either as a string or + * as an array of strings. + * @param {string|Array} value + * @returns {string} + */ + convertText: function(value) { + if (Array.isArray(value)) + return value.join('\n'); + return value; + } +};