Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(jquery): Deprecate renderedText() in favour of JQuery.textWithSha…
Browse files Browse the repository at this point in the history
…dow()
  • Loading branch information
jbdeboer committed Mar 18, 2014
1 parent 9564c07 commit 364d9ff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
38 changes: 19 additions & 19 deletions test/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ es(String html) {

e(String html) => es(html).first;

renderedText(n, [bool notShadow = false]) {

This comment has been minimized.

Copy link
@vicb

vicb Mar 18, 2014

Contributor

This comment has been minimized.

Copy link
@vicb

vicb Mar 18, 2014

Contributor

oops, nevermind that's an other PR

if (n is List) {
return n.map((nn) => renderedText(nn)).join("");
}

if (n is Comment) return '';

if (!notShadow && n is Element && n.shadowRoot != null) {
var shadowText = n.shadowRoot.text;
var domText = renderedText(n, true);
return shadowText.replaceFirst("SHADOW-CONTENT", domText);
}

if (n.nodes == null || n.nodes.length == 0) return n.text;

return n.nodes.map((cn) => renderedText(cn)).join("");
}

Expect expect(actual, [unit.Matcher matcher = null]) {
if (matcher != null) {
unit.expect(actual, matcher);
Expand Down Expand Up @@ -195,6 +177,24 @@ class JQuery extends DelegatingList<Node> {
}
}

_renderedText(n, [bool notShadow = false]) {
if (n is List) {
return n.map((nn) => _renderedText(nn)).join("");
}

if (n is Comment) return '';

if (!notShadow && n is Element && n.shadowRoot != null) {
var shadowText = n.shadowRoot.text;
var domText = _renderedText(n, true);
return shadowText.replaceFirst("SHADOW-CONTENT", domText);
}

if (n.nodes == null || n.nodes.length == 0) return n.text;

return n.nodes.map((cn) => _renderedText(cn)).join("");
}

accessor(Function getter, Function setter, [value, single=false]) {
// TODO(dart): ?value does not work, since value was passed. :-(
var setterMode = value != null;
Expand Down Expand Up @@ -229,7 +229,7 @@ class JQuery extends DelegatingList<Node> {
(n, v) => getterSetter.setter(name)(n, v),
null,
true);
textWithShadow() => fold('', (t, n) => '${t}${renderedText(n)}');
textWithShadow() => fold('', (t, n) => '${t}${_renderedText(n)}');
find(selector) => fold(new JQuery(), (jq, n) => jq..addAll(
(n is Element ? (n as Element).querySelectorAll(selector) : [])));
hasClass(String name) => fold(false, (hasClass, node) =>
Expand Down
36 changes: 19 additions & 17 deletions test/_specs_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,7 @@ library _specs_spec;
import '_specs.dart';

main() {
describe('renderedText', () {
it('should work on regular DOM nodes', () {
expect(renderedText($('<span>A<span>C</span></span><span>B</span>'))).toEqual('ACB');
});

it('should work with shadow DOM', () {
var elt = $('<div>DOM content</div>');
var shadow = elt[0].createShadowRoot();
shadow.setInnerHtml(
'<div>Shadow content</div><content>SHADOW-CONTENT</content>',
treeSanitizer: new NullTreeSanitizer());
expect(renderedText(elt)).toEqual('Shadow contentDOM content');
});

it('should ignore comments', () {
expect(renderedText($('<!--e--><span>A<span>C</span></span><span>B</span>'))).toEqual('ACB');
});
});


describe('jquery', () {
Expand Down Expand Up @@ -59,5 +42,24 @@ main() {
expect(elts.shadowRoot().html()).toEqual('<div>Hello shadow</div>');
});
});

describe('textWithShadow', () {
it('should work on regular DOM nodes', () {
expect($('<span>A<span>C</span></span><span>B</span>').textWithShadow()).toEqual('ACB');
});

it('should work with shadow DOM', () {
var elt = $('<div>DOM content</div>');
var shadow = elt[0].createShadowRoot();
shadow.setInnerHtml(
'<div>Shadow content</div><content>SHADOW-CONTENT</content>',
treeSanitizer: new NullTreeSanitizer());
expect(elt.textWithShadow()).toEqual('Shadow contentDOM content');
});

it('should ignore comments', () {
expect($('<!--e--><span>A<span>C</span></span><span>B</span>').textWithShadow()).toEqual('ACB');
});
});
});
}
6 changes: 3 additions & 3 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ void main() {

microLeap();
_.rootScope.apply();
expect(renderedText(element)).toEqual('inside poof');
expect(element.textWithShadow()).toEqual('inside poof');
}));

it('should behave nicely if a mapped attribute is missing', async((NgZone zone) {
var element = $(_.compile('<parent-expression></parent-expression>'));

microLeap();
_.rootScope.apply();
expect(renderedText(element)).toEqual('inside ');
expect(element.textWithShadow()).toEqual('inside ');
}));

it('should behave nicely if a mapped attribute evals to null', async((NgZone zone) {
Expand All @@ -270,7 +270,7 @@ void main() {

microLeap();
_.rootScope.apply();
expect(renderedText(element)).toEqual('inside ');
expect(element.textWithShadow()).toEqual('inside ');
}));

it('should create a component with I/O', async(() {
Expand Down

0 comments on commit 364d9ff

Please sign in to comment.