📦 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.
This commit is contained in:
parent
3cea203459
commit
d0dc7c5ee1
@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
name: 'hr-card',
|
||||
name: 'card-hr',
|
||||
type: 'dom',
|
||||
render(opts) {
|
||||
return opts.env.dom.createElement('hr');
|
||||
|
@ -3,10 +3,10 @@ var SimpleDom = require('simple-dom'),
|
||||
parser;
|
||||
|
||||
module.exports = {
|
||||
name: 'html-card',
|
||||
name: 'card-html',
|
||||
type: 'dom',
|
||||
render(opts) {
|
||||
parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap);
|
||||
return parser.parse('<div>' + opts.payload.html + '</div>');
|
||||
return parser.parse('<div class="kg-card-html">' + opts.payload.html + '</div>');
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,9 @@
|
||||
module.exports = {
|
||||
name: 'image-card',
|
||||
name: 'card-image',
|
||||
type: 'dom',
|
||||
render(opts) {
|
||||
var img = opts.env.dom.createElement('img');
|
||||
img.className = 'kg-card-image';
|
||||
img.setAttribute('src', opts.payload.img);
|
||||
return img;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ var SimpleDom = require('simple-dom'),
|
||||
parser;
|
||||
|
||||
module.exports = {
|
||||
name: 'markdown-card',
|
||||
name: 'card-markdown',
|
||||
type: 'dom',
|
||||
render(opts) {
|
||||
parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap);
|
||||
return parser.parse('<div>' + converter.makeHtml(opts.payload.markdown || '') + '</div>');
|
||||
return parser.parse('<div class="kg-card-markdown">' + converter.makeHtml(opts.payload.markdown || '') + '</div>');
|
||||
}
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ describe('HTML card', function () {
|
||||
};
|
||||
|
||||
var serializer = new SimpleDom.HTMLSerializer([]);
|
||||
serializer.serialize(card.render(opts)).should.match('<div><h1>HEADING</h1><p>PARAGRAPH</p></div>');
|
||||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-html"><h1>HEADING</h1><p>PARAGRAPH</p></div>');
|
||||
});
|
||||
it('Plain content renders', function () {
|
||||
opts = {
|
||||
@ -28,7 +28,7 @@ describe('HTML card', function () {
|
||||
};
|
||||
|
||||
var serializer = new SimpleDom.HTMLSerializer([]);
|
||||
serializer.serialize(card.render(opts)).should.match('<div>CONTENT</div>');
|
||||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-html">CONTENT</div>');
|
||||
});
|
||||
it.skip('Invalid HTML returns', function () {
|
||||
opts = {
|
||||
@ -41,6 +41,6 @@ describe('HTML card', function () {
|
||||
};
|
||||
|
||||
var serializer = new SimpleDom.HTMLSerializer([]);
|
||||
serializer.serialize(card.render(opts)).should.match('<div><h1>HEADING<</div>');
|
||||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-html"><h1>HEADING<</div>');
|
||||
});
|
||||
});
|
||||
|
@ -15,6 +15,6 @@ describe('Markdown card', function () {
|
||||
};
|
||||
|
||||
var serializer = new SimpleDom.HTMLSerializer([]);
|
||||
serializer.serialize(card.render(opts)).should.match('<div><h1 id="heading">HEADING</h1>\n\n<ul>\n<li>list</li>\n<li>items</li>\n</ul></div>');
|
||||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n\n<ul>\n<li>list</li>\n<li>items</li>\n</ul></div>');
|
||||
});
|
||||
});
|
||||
|
@ -1,11 +1,17 @@
|
||||
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
|
||||
atoms: defaults.atoms,
|
||||
unknownCardHandler: function (args) {
|
||||
var error = new errors.InternalServerError({message: 'Mobiledoc card \'' + args.env.name + '\' not found.'});
|
||||
logging.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// function getCards() {
|
||||
|
@ -6,15 +6,17 @@ describe('Convert mobiledoc to HTML ', function () {
|
||||
version: '0.3.1',
|
||||
atoms: [],
|
||||
cards: [
|
||||
['markdown-card',
|
||||
['card-markdown',
|
||||
{
|
||||
pos: 'top',
|
||||
card_name: 'markdown-card',
|
||||
card_name: 'card-markdown',
|
||||
markdown: '#heading\n\n- list one\n- list two\n- list three'
|
||||
}
|
||||
],
|
||||
['markdown-card', {
|
||||
pos: 'top'
|
||||
['card-html', {
|
||||
pos: 'top',
|
||||
card_name: 'card-html',
|
||||
html: '<p>HTML CARD</p>'
|
||||
}]
|
||||
],
|
||||
markups: [],
|
||||
@ -27,6 +29,6 @@ describe('Convert mobiledoc to HTML ', function () {
|
||||
]
|
||||
};
|
||||
it('Converts a mobiledoc to HTML', function () {
|
||||
converter.render(mobiledoc).should.match('<p>test</p><div><h1 id="heading">heading</h1>\n\n<ul>\n<li>list one</li>\n<li>list two</li>\n<li>list three</li>\n</ul></div><div></div>');
|
||||
converter.render(mobiledoc).should.match('<p>test</p><div class="kg-card-markdown"><h1 id="heading">heading</h1>\n\n<ul>\n<li>list one</li>\n<li>list two</li>\n<li>list three</li>\n</ul></div><div class="kg-card-html"><p>HTML CARD</p></div>');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user