Merge "Plugin endpoint parameters"

This commit is contained in:
Viktar Donich
2017-10-01 08:43:47 +00:00
committed by Gerrit Code Review
5 changed files with 83 additions and 5 deletions

View File

@@ -40,20 +40,41 @@
_initDecoration(name, plugin) {
const el = document.createElement(name);
el.plugin = plugin;
el.content = this.getContentChildren()[0];
this._initProperties(el, plugin, this.getContentChildren().find(
el => el.nodeName !== 'GR-ENDPOINT-PARAM'));
this._appendChild(el);
return el;
},
_initReplacement(name, plugin) {
this.getContentChildren().forEach(node => node.remove());
this.getContentChildNodes().forEach(node => node.remove());
const el = document.createElement(name);
el.plugin = plugin;
this._initProperties(el, plugin);
this._appendChild(el);
return el;
},
_getEndpointParams() {
return Polymer.dom(this).querySelectorAll('gr-endpoint-param').map(el => {
return {name: el.getAttribute('name'), value: el.value};
});
},
/**
* @param {!Element} el
* @param {!Object} plugin
* @param {!Element=} opt_content
*/
_initProperties(el, plugin, opt_content) {
el.plugin = plugin;
if (opt_content) {
el.content = opt_content;
}
for (const {name, value} of this._getEndpointParams()) {
el[name] = value;
}
},
_appendChild(el) {
Polymer.dom(this.root).appendChild(el);
},

View File

@@ -22,10 +22,13 @@ limitations under the License.
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-endpoint-decorator.html">
<link rel="import" href="../gr-endpoint-param/gr-endpoint-param.html">
<test-fixture id="basic">
<template>
<gr-endpoint-decorator name="foo"></gr-endpoint-decorator>
<gr-endpoint-decorator name="foo">
<gr-endpoint-param name="someparam" value="barbar"></gr-endpoint-param>
</gr-endpoint-decorator>
</template>
</test-fixture>
@@ -44,6 +47,7 @@ limitations under the License.
domHookStub = {
handleInstanceAttached: sandbox.stub(),
handleInstanceDetached: sandbox.stub(),
getPublicAPI: () => domHookStub,
};
sandbox.stub(
GrDomHooksManager.prototype, 'getDomHook').returns(domHookStub);
@@ -53,6 +57,7 @@ limitations under the License.
plugin = p;
plugin.registerCustomComponent('foo', 'some-module');
plugin.registerCustomComponent('foo', 'other-module', {replace: true});
plugin.registerCustomComponent('bar', 'some-module');
}, '0.1', 'http://some/plugin/url.html');
sandbox.stub(Gerrit, '_arePluginsLoaded').returns(true);
@@ -110,5 +115,11 @@ limitations under the License.
done();
});
});
test('params', () => {
const instance = document.createElement('foo');
element._initProperties(instance, plugin);
assert.equal(instance.someparam, 'barbar');
});
});
</script>

View File

@@ -0,0 +1,21 @@
<!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<dom-module id="gr-endpoint-param">
<script src="gr-endpoint-param.js"></script>
</dom-module>

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
(function() {
'use strict';
Polymer({
is: 'gr-endpoint-param',
properties: {
name: String,
value: Object,
},
});
})();

View File

@@ -102,6 +102,7 @@ limitations under the License.
'diff/gr-syntax-layer/gr-syntax-layer_test.html',
'diff/gr-syntax-lib-loader/gr-syntax-lib-loader_test.html',
'plugins/gr-attribute-helper/gr-attribute-helper_test.html',
'plugins/gr-endpoint-decorator/gr-endpoint-decorator_test.html',
'plugins/gr-event-helper/gr-event-helper_test.html',
'plugins/gr-external-style/gr-external-style_test.html',
'plugins/gr-plugin-host/gr-plugin-host_test.html',