From 0741114d11b72a1c1177cb6c6fca5e3c6e68ec52 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 19 Mar 2020 12:18:54 +0000 Subject: [PATCH] Moved `htmlToMobiledocConverter()` out of renderers no issue - prep for extraction of various Koenig repos - html->mobiledoc doesn't really fit into the "renderer" naming as it's more of a converter than a renderer and doesn't follow the same pattern --- .../canary/utils/serializers/input/pages.js | 4 ++-- .../canary/utils/serializers/input/posts.js | 4 ++-- .../api/v2/utils/serializers/input/pages.js | 4 ++-- .../api/v2/utils/serializers/input/posts.js | 4 ++-- core/server/lib/mobiledoc/index.js | 22 +++++++++++++++---- core/server/lib/mobiledoc/renderers/index.js | 18 --------------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/core/server/api/canary/utils/serializers/input/pages.js b/core/server/api/canary/utils/serializers/input/pages.js index 4412477562..f858740cb8 100644 --- a/core/server/api/canary/utils/serializers/input/pages.js +++ b/core/server/api/canary/utils/serializers/input/pages.js @@ -1,7 +1,7 @@ const _ = require('lodash'); const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:pages'); const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values'); -const renderers = require('../../../../../lib/mobiledoc/renderers'); +const mobiledoc = require('../../../../../lib/mobiledoc'); const url = require('./utils/url'); const localUtils = require('../../index'); const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta; @@ -143,7 +143,7 @@ module.exports = { const html = frame.data.pages[0].html; if (frame.options.source === 'html' && !_.isEmpty(html)) { - frame.data.pages[0].mobiledoc = JSON.stringify(renderers.htmlToMobiledocConverter(html)); + frame.data.pages[0].mobiledoc = JSON.stringify(mobiledoc.htmlToMobiledocConverter(html)); } } diff --git a/core/server/api/canary/utils/serializers/input/posts.js b/core/server/api/canary/utils/serializers/input/posts.js index 3393fa70ca..2f5f93e167 100644 --- a/core/server/api/canary/utils/serializers/input/posts.js +++ b/core/server/api/canary/utils/serializers/input/posts.js @@ -3,7 +3,7 @@ const debug = require('ghost-ignition').debug('api:canary:utils:serializers:inpu const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values'); const url = require('./utils/url'); const localUtils = require('../../index'); -const renderers = require('../../../../../lib/mobiledoc/renderers'); +const mobiledoc = require('../../../../../lib/mobiledoc'); const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta; const replacePageWithType = mapNQLKeyValues({ @@ -159,7 +159,7 @@ module.exports = { const html = frame.data.posts[0].html; if (frame.options.source === 'html' && !_.isEmpty(html)) { - frame.data.posts[0].mobiledoc = JSON.stringify(renderers.htmlToMobiledocConverter(html)); + frame.data.posts[0].mobiledoc = JSON.stringify(mobiledoc.htmlToMobiledocConverter(html)); } } diff --git a/core/server/api/v2/utils/serializers/input/pages.js b/core/server/api/v2/utils/serializers/input/pages.js index 18f12efce2..21bc94296f 100644 --- a/core/server/api/v2/utils/serializers/input/pages.js +++ b/core/server/api/v2/utils/serializers/input/pages.js @@ -1,7 +1,7 @@ const _ = require('lodash'); const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values'); const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages'); -const renderers = require('../../../../../lib/mobiledoc/renderers'); +const mobiledoc = require('../../../../../lib/mobiledoc'); const url = require('./utils/url'); const localUtils = require('../../index'); const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta; @@ -143,7 +143,7 @@ module.exports = { const html = frame.data.pages[0].html; if (frame.options.source === 'html' && !_.isEmpty(html)) { - frame.data.pages[0].mobiledoc = JSON.stringify(renderers.htmlToMobiledocConverter(html)); + frame.data.pages[0].mobiledoc = JSON.stringify(mobiledoc.htmlToMobiledocConverter(html)); } } diff --git a/core/server/api/v2/utils/serializers/input/posts.js b/core/server/api/v2/utils/serializers/input/posts.js index f6b96e9eb0..519137cadb 100644 --- a/core/server/api/v2/utils/serializers/input/posts.js +++ b/core/server/api/v2/utils/serializers/input/posts.js @@ -3,7 +3,7 @@ const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values'); const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:posts'); const url = require('./utils/url'); const localUtils = require('../../index'); -const renderers = require('../../../../../lib/mobiledoc/renderers'); +const mobiledoc = require('../../../../../lib/mobiledoc'); const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta; const replacePageWithType = mapNQLKeyValues({ @@ -159,7 +159,7 @@ module.exports = { const html = frame.data.posts[0].html; if (frame.options.source === 'html' && !_.isEmpty(html)) { - frame.data.posts[0].mobiledoc = JSON.stringify(renderers.htmlToMobiledocConverter(html)); + frame.data.posts[0].mobiledoc = JSON.stringify(mobiledoc.htmlToMobiledocConverter(html)); } } diff --git a/core/server/lib/mobiledoc/index.js b/core/server/lib/mobiledoc/index.js index 3df3f3df79..e581e31c87 100644 --- a/core/server/lib/mobiledoc/index.js +++ b/core/server/lib/mobiledoc/index.js @@ -1,8 +1,6 @@ -module.exports = { - activate() { - // needed by ghost - }, +const common = require('../common'); +module.exports = { get cards() { return require('./cards'); }, @@ -13,5 +11,21 @@ module.exports = { get renderers() { return require('./renderers'); + }, + + get htmlToMobiledocConverter() { + try { + return require('@tryghost/html-to-mobiledoc').toMobiledoc; + } catch (err) { + return () => { + throw new common.errors.InternalServerError({ + message: 'Unable to convert from source HTML to Mobiledoc', + context: 'The html-to-mobiledoc package was not installed', + help: 'Please review any errors from the install process by checking the Ghost logs', + code: 'HTML_TO_MOBILEDOC_INSTALLATION', + err: err + }); + }; + } } }; diff --git a/core/server/lib/mobiledoc/renderers/index.js b/core/server/lib/mobiledoc/renderers/index.js index c0cc60620b..e430a7287d 100644 --- a/core/server/lib/mobiledoc/renderers/index.js +++ b/core/server/lib/mobiledoc/renderers/index.js @@ -1,5 +1,3 @@ -const common = require('../../common'); - module.exports = { get mobiledocHtmlRenderer() { return require('./mobiledoc-html-renderer'); @@ -7,21 +5,5 @@ module.exports = { get markdownHtmlRenderer() { return require('./markdown-html-renderer'); - }, - - get htmlToMobiledocConverter() { - try { - return require('@tryghost/html-to-mobiledoc').toMobiledoc; - } catch (err) { - return () => { - throw new common.errors.InternalServerError({ - message: 'Unable to convert from source HTML to Mobiledoc', - context: 'The html-to-mobiledoc package was not installed', - help: 'Please review any errors from the install process by checking the Ghost logs', - code: 'HTML_TO_MOBILEDOC_INSTALLATION', - err: err - }); - }; - } } };