Ghost/core/server/utils/mobiledoc-converter.js
Ryan McCarvill d0dc7c5ee1 📦 Card-Rename (#8218)
no issue
- Renames Cards so they comply with the `card-{{name}}` convention rather than `{{name}}-card`
- Adds an unkonwnCardHandler to the editor.
2017-03-24 10:03:33 +00:00

47 lines
1.6 KiB
JavaScript

var SimpleDom = require('simple-dom'),
Renderer = require('mobiledoc-dom-renderer').default,
config = require('../config'),
logging = require('../logging'),
errors = require('../errors'),
defaults = require(config.get('paths').internalAppPath + 'default-cards'),
options = {
dom: new SimpleDom.Document(),
cards: defaults.cards,
atoms: defaults.atoms,
unknownCardHandler: function (args) {
var error = new errors.InternalServerError({message: 'Mobiledoc card \'' + args.env.name + '\' not found.'});
logging.error(error);
}
};
// function getCards() {
// return config.get('internalApps').reduce(
// function (cards, appName) {
// var app = require(path.join(config.get('paths').internalAppPath, appName));
// if (app.hasOwnProperty('cards')) {
// cards = cards.concat(app.cards);
// }
// return cards;
// }, [ ]);
// }
// function getAtoms() {
// return config.get('internalApps').reduce(
// function (atoms, appName) {
// var app = require(path.join(config.get('paths').internalAppPath, appName));
// if (app.hasOwnProperty('atoms')) {
// atoms = atoms.concat(app.atoms);
// }
// return atoms;
// }, [ ]);
// }
module.exports = {
render: function (mobiledoc) {
var renderer = new Renderer(options),
rendered = renderer.render(mobiledoc),
serializer = new SimpleDom.HTMLSerializer([]),
html = serializer.serializeChildren(rendered.result);
return html;
}
};