Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new way of loading v2 widgets #4

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion root/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"js_files": [
"js/{%= jsname %}.js"
],
"entrypoint": "js/{%= entrypoint %}.js",
"title": "{%= project_name %}",
"translations": {},
"type": "widget",
Expand Down
1 change: 0 additions & 1 deletion root/src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<scripts>
<script src="js/{%= jsname %}.js"/>
</scripts>
<entrypoint name="{%= entrypoint %}"/>
<rendering height="300px" width="30%"/>

</widget>
16 changes: 9 additions & 7 deletions root/src/js/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/

/* exported {%= entrypoint %} */

(function () {
(function (script) {

"use strict";

// =========================================================================
// CLASS DEFINITION
// =========================================================================

class {%= entrypoint %} {
class Widget {
constructor(MashupPlatform, shadowDOM, extra) {
this.MashupPlatform = MashupPlatform;
this.shadowDOM = shadowDOM;
Expand All @@ -27,11 +25,15 @@
}
}

// We define the class as part of the window object so that it can be instantiated by Wirecloud
window.{%= entrypoint %} = {%= entrypoint %};
if (!('Wirecloud' in window)) {
// For testing purposes
window.Widget = Widget;
} else {
Wirecloud.registerWidgetClass(script, Widget);
}

/* test-code */

/* end-test-code */

})();
})(document.currentScript);
9 changes: 6 additions & 3 deletions root/src/ts/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MashupPlatform = require("MashupPlatform");
{% if (ngsi) { %}import NGSI = require("NGSI");{% }%}
/* end-import-block */

export class {%= entrypoint %} {
export class Widget {
private MashupPlatform: MashupPlatform;
private shadowDOM: any;
{% if (ngsi) { %}private NGSI: NGSI;{% }%}
Expand All @@ -27,5 +27,8 @@ export class {%= entrypoint %} {
}
}

// We define the class as part of the window object so that it can be instantiated by Wirecloud
(<any>window)["{%= entrypoint %}"] = {%= entrypoint %};
if (!(<any>window).Wirecloud) {
(<any>window).Widget = Widget;
} else {
(<any>window).Wirecloud.registerWidgetClass((<any>document).currentScript, Widget);
}
7 changes: 5 additions & 2 deletions root/tests/js/nameSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/

/* globals $, MashupPlatform, MockMP, {%= entrypoint %} */
/* globals $, MashupPlatform, MockMP */

(function () {

Expand All @@ -16,16 +16,19 @@

var widget;
var MashupPlatform;
var Widget;

beforeAll(function () {
MashupPlatform = new MockMP({
type: 'widget'
});

Widget = window.Widget;
});

beforeEach(function () {
MashupPlatform.reset();
widget = new {%= entrypoint %}(MashupPlatform, undefined, {});
widget = new Widget(MashupPlatform, undefined, {});
});

it("Dummy test", function () {
Expand Down
8 changes: 0 additions & 8 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ var capitalizeAndRemoveUnderscore = function capitalizeAndRemoveUnderscore(old)
return t.charAt(0).toUpperCase() + t.slice(1);
};

var getEntrypointName = function getEntrypointName(vendor, name) {
// Remove all non-alphanumeric characters. Replace spaces with underscores.
vendor = vendor.replace(/[^a-zA-Z0-9]/g, '').replace(/\s/g, '_');
name = name.replace(/[^a-zA-Z0-9]/g, '').replace(/\s/g, '_');
return vendor + '_' + name;
}

// The actual init template.
exports.template = function(grunt, init, done) {
init.process([
Expand Down Expand Up @@ -130,7 +123,6 @@ exports.template = function(grunt, init, done) {
], function(err, props){
var exportsOverride = {};
props.jsname = capitalizeAndRemoveUnderscore(props.name);
props.entrypoint = getEntrypointName(props.vendor, props.name);
props.bower = true; // Change way to determine bower?
props.ngsi = false; // ??
var bowerdeps = {};
Expand Down