Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.

Commit 6021b45

Browse files
committed
Add temporary workaround for SimpleDOM
The current parseHTML implementation requires some DOM APIs not implemented in SimpleDOM. This commit adds a temporary workaround to support using SimpleDOM on the server. In the future, we will move towards using `insertAdjacentHTML` and `innerHTML=` as the main APIs and remove the need of `parseHTML` altogether. This commit also reverts a previous commit that introduced the `setMorphHTML` method, which does exactly what `Morph#setHTML` does.
1 parent b0994e1 commit 6021b45

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
"emberjs-build": "0.2.1",
4545
"git-repo-version": "^0.1.2",
4646
"handlebars": "^3.0.2",
47-
"morph-range": "0.2.5",
47+
"morph-range": "0.3.0",
4848
"qunit": "^0.7.2",
49-
"rsvp": "~3.0.6"
49+
"rsvp": "~3.0.6",
50+
"simple-dom": "~0.2.4"
5051
}
5152
}

packages/dom-helper/lib/main.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,23 @@ prototype.insertBoundary = function(fragment, index) {
519519
this.insertBefore(fragment, this.createTextNode(''), child);
520520
};
521521

522-
prototype.setMorphHTML = function(morph, html) {
523-
morph.setHTML(html);
522+
// We plan to remove this eventually, and move to using `setInnerHTML`
523+
// and `insertAdjacentHTML` as the main APIs, so please try not to
524+
// introduce new usage if it can be avoided.
525+
prototype.parseHTML = function(html, contextualElement) {
526+
if (typeof this.document.createRawHTMLSection === 'function') {
527+
// Temporary workaround to support SimpleDOM in node
528+
return this._createRawHTMLSection(html);
529+
}
530+
531+
return this._createDocumentFragmentFromHTML(html, contextualElement);
524532
};
525533

526-
prototype.parseHTML = function(html, contextualElement) {
534+
prototype._createRawHTMLSection = function(html) {
535+
return this.document.createRawHTMLSection(html);
536+
};
537+
538+
prototype._createDocumentFragmentFromHTML = function(html, contextualElement) {
527539
var childNodes;
528540

529541
if (interiorNamespace(contextualElement) === svgNamespace) {

packages/dom-helper/tests/dom-helper-node-test.js

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
/*globals require*/
2+
13
import DOMHelper from "../dom-helper";
24

5+
var SimpleDOM = require('simple-dom');
6+
37
var dom;
48

59
QUnit.module('DOM Helper (Node)', {
@@ -34,3 +38,27 @@ test('it instantiates with a stub document', function(){
3438
var createdElement = dom.createElement('div');
3539
equal(createdElement, element, 'dom helper calls passed stub');
3640
});
41+
42+
QUnit.module('DOM Helper (Integration: SimpleDOM)', {
43+
afterEach: function() {
44+
dom = null;
45+
}
46+
});
47+
48+
test('it instantiates with a SimpleDOM document', function(){
49+
var doc = new SimpleDOM.Document();
50+
dom = new DOMHelper(doc);
51+
ok(dom, 'dom helper can instantiate');
52+
var createdElement = dom.createElement('div');
53+
equal(createdElement.tagName, 'DIV', 'dom helper calls passed stub');
54+
});
55+
56+
test('it does not parse HTML', function(){
57+
var doc = new SimpleDOM.Document();
58+
dom = new DOMHelper(doc);
59+
ok(dom, 'dom helper can instantiate');
60+
var parsed = dom.parseHTML('<div>Hello</div>');
61+
equal(parsed.nodeType, -1, 'parseHTML creates a RawHTMLSection');
62+
equal(parsed.nodeName, '#raw-html-section', 'parseHTML creates a RawHTMLSection');
63+
equal(parsed.nodeValue, '<div>Hello</div>', 'parseHTML creates a RawHTMLSection');
64+
});

0 commit comments

Comments
 (0)