fix(html_adapter): Implement hasAttribute and getAttribute.
Fixes the template compiler when running on the server.
This commit is contained in:
parent
3810e4bed3
commit
e988f59c08
|
@ -13,7 +13,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
hasProperty(element, String name) {
|
||||
// This is needed for serverside compile to generate the right getters/setters.
|
||||
// TODO: change this once we have property schema support.
|
||||
// Attention: Keep this in sync with browser_adapter.dart!
|
||||
// Attention: Keep this in sync with browser_adapter.dart!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -235,10 +235,14 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
return map;
|
||||
}
|
||||
hasAttribute(element, String attribute) {
|
||||
throw 'not implemented';
|
||||
// `attributes` keys can be {@link AttributeName}s.
|
||||
return element.attributes.keys.any((key) => '$key' == attribute);
|
||||
}
|
||||
getAttribute(element, String attribute) {
|
||||
throw 'not implemented';
|
||||
// `attributes` keys can be {@link AttributeName}s.
|
||||
var key = element.attributes.keys.firstWhere(
|
||||
(key) => '$key' == attribute, orElse: () {});
|
||||
return element.attributes[key];
|
||||
}
|
||||
setAttribute(element, String name, String value) {
|
||||
element.attributes[name] = value;
|
||||
|
|
|
@ -16,5 +16,19 @@ main() {
|
|||
it('should parse HTML', () {
|
||||
expect(subject.parse('<div>hi</div>'), isNotNull);
|
||||
});
|
||||
|
||||
it('implements hasAttribute', () {
|
||||
var div = subject.querySelector(
|
||||
subject.parse('<div foo="bar"></div>'), ('div'));
|
||||
expect(subject.hasAttribute(div, 'foo')).toBeTrue();
|
||||
expect(subject.hasAttribute(div, 'bar')).toBeFalse();
|
||||
});
|
||||
|
||||
it('implements getAttribute', () {
|
||||
var div = subject.querySelector(
|
||||
subject.parse('<div foo="bar"></div>'), ('div'));
|
||||
expect(subject.getAttribute(div, 'foo')).toEqual('bar');
|
||||
expect(subject.getAttribute(div, 'bar')).toBe(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue