Skip to content

Commit

Permalink
Catch render errors in demo and display the error
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Aug 27, 2015
1 parent 04cfdc7 commit 789e252
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ var ContentKitDemo = exports.ContentKitDemo = {
'image': ContentKit.ImageCard
};
var renderer = new MobiledocDOMRenderer();
var rendered = renderer.render(mobiledoc, document.createElement('div'), cards);
var rendered;
try {
rendered = renderer.render(mobiledoc, document.createElement('div'), cards);
} catch (e) {
rendered = document.createTextNode('Error rendering: ' + e);
}

$('#rendered-mobiledoc').empty();
$('#rendered-mobiledoc')[0].appendChild(rendered);
Expand Down Expand Up @@ -234,7 +239,14 @@ var ContentKitDemo = exports.ContentKitDemo = {
};

var htmlRenderer = new MobiledocHTMLRenderer();
$('#rendered-mobiledoc-html').html(displayHTML(htmlRenderer.render(mobiledoc)));
var renderedHTML;
try {
renderedHTML = htmlRenderer.render(mobiledoc);
} catch (e) {
renderedHTML = 'Error rendering: ' + e;
}

$('#rendered-mobiledoc-html').html(displayHTML(renderedHTML));

var editorHTML = debugNodeHTML($('#editor')[0]);
$('#editor-html').html(editorHTML);
Expand Down Expand Up @@ -314,7 +326,7 @@ function attemptEditorReboot(editor, textPayload) {

var MOBILEDOC_VERSION = "0.1";
var sampleMobiledocs = {
simpleMobiledoc: {
xsimpleMobiledoc: {
version: MOBILEDOC_VERSION,
sections: [
[],
Expand All @@ -329,6 +341,26 @@ var sampleMobiledocs = {
]
},

//simpleMobiledocWithList: {
simpleMobiledoc: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "To do today:"]
]],
[1, "UL", [
[
[[], 0, "buy milk"],
[[], 0, "water cows"],
[[], 0, "world domination"]
]
]]
]
]
},

mobileDocWithMarker: {
version: MOBILEDOC_VERSION,
sections: [
Expand Down

0 comments on commit 789e252

Please sign in to comment.