mobiledoc-dom-renderer
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -1,2 +0,28 @@ | ||
define('mobiledoc-dom-renderer/dom-renderer', ['exports'], function (exports) { | ||
define('mobiledoc-dom-renderer/cards/image', ['exports', 'mobiledoc-dom-renderer/cards/utils'], function (exports, _mobiledocDomRendererCardsUtils) { | ||
'use strict'; | ||
var ImageCard = { | ||
name: 'image', | ||
display: { | ||
setup: function setup(element, options, env, payload) { | ||
if (payload.src) { | ||
var img = (0, _mobiledocDomRendererCardsUtils.createElement)('img'); | ||
img.src = payload.src; | ||
element.appendChild(img); | ||
} | ||
} | ||
} | ||
}; | ||
exports['default'] = ImageCard; | ||
}); | ||
define("mobiledoc-dom-renderer/dom-renderer", ["exports", "mobiledoc-dom-renderer/utils", "mobiledoc-dom-renderer/cards/image"], function (exports, _mobiledocDomRendererUtils, _mobiledocDomRendererCardsImage) { | ||
"use strict"; | ||
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })(); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
@@ -10,22 +36,2 @@ * runtime DOM renderer | ||
'use strict'; | ||
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var utils = { | ||
createElement: function createElement(tagName) { | ||
return document.createElement(tagName); | ||
}, | ||
appendChild: function appendChild(target, child) { | ||
target.appendChild(child); | ||
}, | ||
createTextNode: function createTextNode(text) { | ||
return document.createTextNode(text); | ||
} | ||
}; | ||
function createElementFromMarkerType() { | ||
@@ -39,3 +45,3 @@ var _ref = arguments.length <= 0 || arguments[0] === undefined ? ['', []] : arguments[0]; | ||
var element = utils.createElement(tagName); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)(tagName); | ||
attributes = attributes || []; | ||
@@ -51,2 +57,6 @@ | ||
function setDefaultCards(cards) { | ||
cards.image = cards.image || _mobiledocDomRendererCardsImage["default"]; | ||
} | ||
var DOMRenderer = (function () { | ||
@@ -58,3 +68,3 @@ function DOMRenderer() { | ||
_createClass(DOMRenderer, [{ | ||
key: 'render', | ||
key: "render", | ||
@@ -69,3 +79,3 @@ /** | ||
var rootElement = arguments.length <= 1 || arguments[1] === undefined ? utils.createElement('div') : arguments[1]; | ||
var rootElement = arguments.length <= 1 || arguments[1] === undefined ? (0, _mobiledocDomRendererUtils.createElement)('div') : arguments[1]; | ||
var version = _ref3.version; | ||
@@ -83,2 +93,3 @@ var sectionData = _ref3.sections; | ||
this.cards = cards; | ||
setDefaultCards(this.cards); | ||
@@ -92,3 +103,3 @@ sections.forEach(function (section) { | ||
}, { | ||
key: 'renderSection', | ||
key: "renderSection", | ||
value: function renderSection(section) { | ||
@@ -103,11 +114,11 @@ var _section = _slicedToArray(section, 1); | ||
rendered = this.renderMarkupSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
case 2: | ||
rendered = this.renderImageSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
case 10: | ||
rendered = this.renderCardSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
@@ -119,3 +130,3 @@ default: | ||
}, { | ||
key: 'renderImageSection', | ||
key: "renderImageSection", | ||
value: function renderImageSection(_ref4) { | ||
@@ -127,3 +138,3 @@ var _ref42 = _slicedToArray(_ref4, 2); | ||
var element = utils.createElement('img'); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)('img'); | ||
element.src = src; | ||
@@ -133,3 +144,3 @@ return element; | ||
}, { | ||
key: 'renderCardSection', | ||
key: "renderCardSection", | ||
value: function renderCardSection(_ref5) { | ||
@@ -144,5 +155,5 @@ var _ref52 = _slicedToArray(_ref5, 3); | ||
if (!card) { | ||
throw new Error('Cannot render unknown card named ' + name); | ||
throw new Error("Cannot render unknown card named " + name); | ||
} | ||
var element = utils.createElement('div'); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)('div'); | ||
card.display.setup(element, {}, { name: name }, payload); | ||
@@ -152,3 +163,3 @@ return element; | ||
}, { | ||
key: 'renderMarkupSection', | ||
key: "renderMarkupSection", | ||
value: function renderMarkupSection(_ref6) { | ||
@@ -161,3 +172,3 @@ var _ref62 = _slicedToArray(_ref6, 3); | ||
var element = utils.createElement(tagName); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)(tagName); | ||
var elements = [element]; | ||
@@ -178,3 +189,3 @@ var currentElement = element; | ||
var openedElement = createElementFromMarkerType(markerType); | ||
utils.appendChild(currentElement, openedElement); | ||
(0, _mobiledocDomRendererUtils.appendChild)(currentElement, openedElement); | ||
elements.push(openedElement); | ||
@@ -184,3 +195,3 @@ currentElement = openedElement; | ||
utils.appendChild(currentElement, utils.createTextNode(text)); | ||
(0, _mobiledocDomRendererUtils.appendChild)(currentElement, (0, _mobiledocDomRendererUtils.createTextNode)(text)); | ||
@@ -200,3 +211,3 @@ for (var j = 0, m = closeTypes; j < m; j++) { | ||
exports['default'] = DOMRenderer; | ||
exports["default"] = DOMRenderer; | ||
}); | ||
@@ -213,2 +224,21 @@ define('mobiledoc-dom-renderer', ['exports', 'mobiledoc-dom-renderer/dom-renderer'], function (exports, _mobiledocDomRendererDomRenderer) { | ||
exports['default'] = _mobiledocDomRendererDomRenderer['default']; | ||
}); | ||
define("mobiledoc-dom-renderer/utils", ["exports"], function (exports) { | ||
"use strict"; | ||
exports.createElement = createElement; | ||
exports.appendChild = appendChild; | ||
exports.createTextNode = createTextNode; | ||
function createElement(tagName) { | ||
return document.createElement(tagName); | ||
} | ||
function appendChild(target, child) { | ||
target.appendChild(child); | ||
} | ||
function createTextNode(text) { | ||
return document.createTextNode(text); | ||
} | ||
}); |
@@ -16,3 +16,4 @@ ;(function() { | ||
var registry = {}, seen = {}; | ||
var registry = {}; | ||
var seen = {}; | ||
var FAILED = false; | ||
@@ -124,3 +125,2 @@ | ||
if (mod && mod.callback instanceof Alias) { | ||
@@ -184,4 +184,5 @@ mod = registry[mod.callback.name]; | ||
parentBase.pop(); | ||
} else if (part === '.') { continue; } | ||
else { parentBase.push(part); } | ||
} else if (part === '.') { | ||
continue; | ||
} else { parentBase.push(part); } | ||
} | ||
@@ -193,3 +194,7 @@ | ||
requirejs.entries = requirejs._eak_seen = registry; | ||
requirejs.clear = function(){ | ||
requirejs.unsee = function(moduleName) { | ||
delete seen[moduleName]; | ||
}; | ||
requirejs.clear = function() { | ||
requirejs.entries = requirejs._eak_seen = registry = {}; | ||
@@ -200,3 +205,29 @@ seen = state = {}; | ||
define('mobiledoc-dom-renderer/dom-renderer', ['exports'], function (exports) { | ||
define('mobiledoc-dom-renderer/cards/image', ['exports', 'mobiledoc-dom-renderer/cards/utils'], function (exports, _mobiledocDomRendererCardsUtils) { | ||
'use strict'; | ||
var ImageCard = { | ||
name: 'image', | ||
display: { | ||
setup: function setup(element, options, env, payload) { | ||
if (payload.src) { | ||
var img = (0, _mobiledocDomRendererCardsUtils.createElement)('img'); | ||
img.src = payload.src; | ||
element.appendChild(img); | ||
} | ||
} | ||
} | ||
}; | ||
exports['default'] = ImageCard; | ||
}); | ||
define("mobiledoc-dom-renderer/dom-renderer", ["exports", "mobiledoc-dom-renderer/utils", "mobiledoc-dom-renderer/cards/image"], function (exports, _mobiledocDomRendererUtils, _mobiledocDomRendererCardsImage) { | ||
"use strict"; | ||
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })(); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
@@ -210,22 +241,2 @@ * runtime DOM renderer | ||
'use strict'; | ||
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var utils = { | ||
createElement: function createElement(tagName) { | ||
return document.createElement(tagName); | ||
}, | ||
appendChild: function appendChild(target, child) { | ||
target.appendChild(child); | ||
}, | ||
createTextNode: function createTextNode(text) { | ||
return document.createTextNode(text); | ||
} | ||
}; | ||
function createElementFromMarkerType() { | ||
@@ -239,3 +250,3 @@ var _ref = arguments.length <= 0 || arguments[0] === undefined ? ['', []] : arguments[0]; | ||
var element = utils.createElement(tagName); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)(tagName); | ||
attributes = attributes || []; | ||
@@ -251,2 +262,6 @@ | ||
function setDefaultCards(cards) { | ||
cards.image = cards.image || _mobiledocDomRendererCardsImage["default"]; | ||
} | ||
var DOMRenderer = (function () { | ||
@@ -258,3 +273,3 @@ function DOMRenderer() { | ||
_createClass(DOMRenderer, [{ | ||
key: 'render', | ||
key: "render", | ||
@@ -269,3 +284,3 @@ /** | ||
var rootElement = arguments.length <= 1 || arguments[1] === undefined ? utils.createElement('div') : arguments[1]; | ||
var rootElement = arguments.length <= 1 || arguments[1] === undefined ? (0, _mobiledocDomRendererUtils.createElement)('div') : arguments[1]; | ||
var version = _ref3.version; | ||
@@ -283,2 +298,3 @@ var sectionData = _ref3.sections; | ||
this.cards = cards; | ||
setDefaultCards(this.cards); | ||
@@ -292,3 +308,3 @@ sections.forEach(function (section) { | ||
}, { | ||
key: 'renderSection', | ||
key: "renderSection", | ||
value: function renderSection(section) { | ||
@@ -303,11 +319,11 @@ var _section = _slicedToArray(section, 1); | ||
rendered = this.renderMarkupSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
case 2: | ||
rendered = this.renderImageSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
case 10: | ||
rendered = this.renderCardSection(section); | ||
utils.appendChild(this.root, rendered); | ||
(0, _mobiledocDomRendererUtils.appendChild)(this.root, rendered); | ||
break; | ||
@@ -319,3 +335,3 @@ default: | ||
}, { | ||
key: 'renderImageSection', | ||
key: "renderImageSection", | ||
value: function renderImageSection(_ref4) { | ||
@@ -327,3 +343,3 @@ var _ref42 = _slicedToArray(_ref4, 2); | ||
var element = utils.createElement('img'); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)('img'); | ||
element.src = src; | ||
@@ -333,3 +349,3 @@ return element; | ||
}, { | ||
key: 'renderCardSection', | ||
key: "renderCardSection", | ||
value: function renderCardSection(_ref5) { | ||
@@ -344,5 +360,5 @@ var _ref52 = _slicedToArray(_ref5, 3); | ||
if (!card) { | ||
throw new Error('Cannot render unknown card named ' + name); | ||
throw new Error("Cannot render unknown card named " + name); | ||
} | ||
var element = utils.createElement('div'); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)('div'); | ||
card.display.setup(element, {}, { name: name }, payload); | ||
@@ -352,3 +368,3 @@ return element; | ||
}, { | ||
key: 'renderMarkupSection', | ||
key: "renderMarkupSection", | ||
value: function renderMarkupSection(_ref6) { | ||
@@ -361,3 +377,3 @@ var _ref62 = _slicedToArray(_ref6, 3); | ||
var element = utils.createElement(tagName); | ||
var element = (0, _mobiledocDomRendererUtils.createElement)(tagName); | ||
var elements = [element]; | ||
@@ -378,3 +394,3 @@ var currentElement = element; | ||
var openedElement = createElementFromMarkerType(markerType); | ||
utils.appendChild(currentElement, openedElement); | ||
(0, _mobiledocDomRendererUtils.appendChild)(currentElement, openedElement); | ||
elements.push(openedElement); | ||
@@ -384,3 +400,3 @@ currentElement = openedElement; | ||
utils.appendChild(currentElement, utils.createTextNode(text)); | ||
(0, _mobiledocDomRendererUtils.appendChild)(currentElement, (0, _mobiledocDomRendererUtils.createTextNode)(text)); | ||
@@ -400,3 +416,3 @@ for (var j = 0, m = closeTypes; j < m; j++) { | ||
exports['default'] = DOMRenderer; | ||
exports["default"] = DOMRenderer; | ||
}); | ||
@@ -414,3 +430,22 @@ define('mobiledoc-dom-renderer', ['exports', 'mobiledoc-dom-renderer/dom-renderer'], function (exports, _mobiledocDomRendererDomRenderer) { | ||
}); | ||
define("mobiledoc-dom-renderer/utils", ["exports"], function (exports) { | ||
"use strict"; | ||
exports.createElement = createElement; | ||
exports.appendChild = appendChild; | ||
exports.createTextNode = createTextNode; | ||
function createElement(tagName) { | ||
return document.createElement(tagName); | ||
} | ||
function appendChild(target, child) { | ||
target.appendChild(child); | ||
} | ||
function createTextNode(text) { | ||
return document.createTextNode(text); | ||
} | ||
}); | ||
require("mobiledoc-dom-renderer")["registerGlobal"](window, document); | ||
})(); |
@@ -0,1 +1,6 @@ | ||
module('JSHint - tests/jshint/cards'); | ||
test('tests/jshint/cards/image.js should pass jshint', function() { | ||
ok(true, 'tests/jshint/cards/image.js should pass jshint.'); | ||
}); | ||
module('JSHint - tests/jshint'); | ||
@@ -16,2 +21,7 @@ test('tests/jshint/dom-renderer.js should pass jshint', function() { | ||
module('JSHint - tests/jshint'); | ||
test('tests/jshint/utils.js should pass jshint', function() { | ||
ok(true, 'tests/jshint/utils.js should pass jshint.'); | ||
}); | ||
define('tests/unit/dom-renderer-test', ['exports', 'mobiledoc-dom-renderer'], function (exports, _mobiledocDomRenderer) { | ||
@@ -114,3 +124,3 @@ /* global QUnit */ | ||
test('renders a mobiledoc with image section', function (assert) { | ||
var url = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs='; | ||
var url = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs="; | ||
var mobiledoc = { | ||
@@ -156,2 +166,22 @@ versions: MOBILEDOC_VERSION, | ||
}); | ||
test('renders a mobiledoc with default image section', function (assert) { | ||
assert.expect(3); | ||
var cardName = 'image'; | ||
var payload = { | ||
src: 'example.org/foo.jpg' | ||
}; | ||
var mobiledoc = { | ||
version: MOBILEDOC_VERSION, | ||
sections: [[], // markers | ||
[// sections | ||
[10, cardName, payload]]] | ||
}; | ||
var rendered = renderer.render(mobiledoc, document.createElement('div')); | ||
assert.equal(rendered.childNodes.length, 1, 'renders 1 section'); | ||
var sectionEl = rendered.childNodes[0]; | ||
assert.equal(sectionEl.firstChild.tagName, 'IMG'); | ||
assert.equal(sectionEl.firstChild.src, 'example.org/foo.jpg'); | ||
}); | ||
}); |
@@ -14,3 +14,4 @@ var define, requireModule, require, requirejs; | ||
var registry = {}, seen = {}; | ||
var registry = {}; | ||
var seen = {}; | ||
var FAILED = false; | ||
@@ -122,3 +123,2 @@ | ||
if (mod && mod.callback instanceof Alias) { | ||
@@ -182,4 +182,5 @@ mod = registry[mod.callback.name]; | ||
parentBase.pop(); | ||
} else if (part === '.') { continue; } | ||
else { parentBase.push(part); } | ||
} else if (part === '.') { | ||
continue; | ||
} else { parentBase.push(part); } | ||
} | ||
@@ -191,3 +192,7 @@ | ||
requirejs.entries = requirejs._eak_seen = registry; | ||
requirejs.clear = function(){ | ||
requirejs.unsee = function(moduleName) { | ||
delete seen[moduleName]; | ||
}; | ||
requirejs.clear = function() { | ||
requirejs.entries = requirejs._eak_seen = registry = {}; | ||
@@ -194,0 +199,0 @@ seen = state = {}; |
@@ -0,1 +1,8 @@ | ||
import { | ||
createElement, | ||
appendChild, | ||
createTextNode | ||
} from "./utils"; | ||
import ImageCard from "./cards/image"; | ||
/** | ||
@@ -9,16 +16,4 @@ * runtime DOM renderer | ||
const utils = { | ||
createElement(tagName) { | ||
return document.createElement(tagName); | ||
}, | ||
appendChild(target, child) { | ||
target.appendChild(child); | ||
}, | ||
createTextNode(text) { | ||
return document.createTextNode(text); | ||
} | ||
}; | ||
function createElementFromMarkerType([tagName, attributes]=['', []]){ | ||
let element = utils.createElement(tagName); | ||
let element = createElement(tagName); | ||
attributes = attributes || []; | ||
@@ -34,2 +29,6 @@ | ||
function setDefaultCards(cards) { | ||
cards.image = cards.image || ImageCard; | ||
} | ||
export default class DOMRenderer { | ||
@@ -41,3 +40,3 @@ /** | ||
*/ | ||
render({version, sections: sectionData}, rootElement=utils.createElement('div'), cards={}) { | ||
render({version, sections: sectionData}, rootElement=createElement('div'), cards={}) { | ||
const [markerTypes, sections] = sectionData; | ||
@@ -47,2 +46,3 @@ this.root = rootElement; | ||
this.cards = cards; | ||
setDefaultCards(this.cards); | ||
@@ -60,11 +60,11 @@ sections.forEach((section) => this.renderSection(section)); | ||
rendered = this.renderMarkupSection(section); | ||
utils.appendChild(this.root, rendered); | ||
appendChild(this.root, rendered); | ||
break; | ||
case 2: | ||
rendered = this.renderImageSection(section); | ||
utils.appendChild(this.root, rendered); | ||
appendChild(this.root, rendered); | ||
break; | ||
case 10: | ||
rendered = this.renderCardSection(section); | ||
utils.appendChild(this.root, rendered); | ||
appendChild(this.root, rendered); | ||
break; | ||
@@ -77,3 +77,3 @@ default: | ||
renderImageSection([type, src]) { | ||
let element = utils.createElement('img'); | ||
let element = createElement('img'); | ||
element.src = src; | ||
@@ -88,3 +88,3 @@ return element; | ||
} | ||
let element = utils.createElement('div'); | ||
let element = createElement('div'); | ||
card.display.setup(element, {}, {name}, payload); | ||
@@ -95,3 +95,3 @@ return element; | ||
renderMarkupSection([type, tagName, markers]) { | ||
let element = utils.createElement(tagName); | ||
let element = createElement(tagName); | ||
let elements = [element]; | ||
@@ -107,3 +107,3 @@ let currentElement = element; | ||
let openedElement = createElementFromMarkerType(markerType); | ||
utils.appendChild(currentElement, openedElement); | ||
appendChild(currentElement, openedElement); | ||
elements.push(openedElement); | ||
@@ -113,3 +113,3 @@ currentElement = openedElement; | ||
utils.appendChild(currentElement, utils.createTextNode(text)); | ||
appendChild(currentElement, createTextNode(text)); | ||
@@ -116,0 +116,0 @@ for (let j=0, m=closeTypes; j<m; j++) { |
{ | ||
"name": "mobiledoc-dom-renderer", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Renders Mobiledoc input to DOM output", | ||
@@ -5,0 +5,0 @@ "main": "dist/global/mobiledoc-dom-renderer.js", |
## Mobiledoc DOM Renderer [![Build Status](https://travis-ci.org/bustlelabs/mobiledoc-dom-renderer.svg?branch=master)](https://travis-ci.org/bustlelabs/mobiledoc-dom-renderer) | ||
This is a runtime renderer for the `mobiledoc` format. | ||
It renders mobiledoc to DOM elements. | ||
This is a DOM renderer for the [Mobiledoc](https://github.com/bustlelabs/content-kit-editor/blob/master/MOBILEDOC.md) format used | ||
by the [Content-Kit Editor](https://github.com/bustlelabs/content-kit-editor). | ||
It is intended to be a small libraray that is run client-side in a browser that wants to display mobiledoc. | ||
The renderer is a small library intended for use in browser clients. | ||
@@ -11,19 +11,23 @@ ### Usage | ||
``` | ||
var mobiledoc = [ | ||
[ // markers | ||
['B'] | ||
], | ||
[ // sections | ||
[1, 'P', [ // array of markups | ||
// markup | ||
[ | ||
[0], // open markers (by index) | ||
0, // close count | ||
'hello world' | ||
var mobiledoc = { | ||
version: "0.1", | ||
sections: [ | ||
[ // markers | ||
['B'] | ||
], | ||
[ // sections | ||
[1, 'P', [ // array of markups | ||
// markup | ||
[ | ||
[0], // open markers (by index) | ||
0, // close count | ||
'hello world' | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
}; | ||
var renderer = new DOMRenderer(); | ||
var rendered = renderer.render(mobiledoc); | ||
var cards = {}; | ||
var rendered = renderer.render(mobiledoc, document.createElement('div'), cards); | ||
document.getElementById('output').appendChild(rendered); | ||
@@ -30,0 +34,0 @@ // renders <div><p><b>hello world</b></b></div> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159940
14
4548
47