aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-18 12:34:29 -0700
committerJose Antonio Marquez2012-03-18 12:34:29 -0700
commitfda7b595c96d99177fdd93de8da9030348a3f8fb (patch)
treeee4c787e3ab4312835e95a83bdf94f52fadee52f
parent954f5a13e371febcb1c0fb8015c577ee51c23130 (diff)
downloadninja-fda7b595c96d99177fdd93de8da9030348a3f8fb.tar.gz
Temp I/O functionality for M-JS components
Added the ability to save montages component serialization from Ninja. Very rough, but functional.
-rwxr-xr-xjs/document/html-document.js4
-rw-r--r--js/io/system/ninjalibrary.json4
-rw-r--r--js/mediators/io-mediator.js70
-rw-r--r--node_modules/descriptor.json9
-rw-r--r--node_modules/tools/template-creator.js12
5 files changed, 80 insertions, 19 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index d4db6e2f..be1f89e2 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -905,7 +905,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
905 } 905 }
906 } 906 }
907 } 907 }
908 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 908 return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
909 } else if (this.currentView === "code"){ 909 } else if (this.currentView === "code"){
910 //TODO: Would this get call when we are in code of HTML? 910 //TODO: Would this get call when we are in code of HTML?
911 } else { 911 } else {
@@ -928,7 +928,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
928 } 928 }
929 } 929 }
930 } 930 }
931 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 931 return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
932 } else if (this.currentView === "code"){ 932 } else if (this.currentView === "code"){
933 //TODO: Would this get call when we are in code of HTML? 933 //TODO: Would this get call when we are in code of HTML?
934 } else { 934 } else {
diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json
index 00ee7ed2..42505e38 100644
--- a/js/io/system/ninjalibrary.json
+++ b/js/io/system/ninjalibrary.json
@@ -1,6 +1,6 @@
1{ 1{
2 "libraries": [ 2 "libraries": [
3 {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.6.0.0"}, 3 {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.7.0.0"},
4 {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.1.0"} 4 {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.1.1"}
5 ] 5 ]
6} \ No newline at end of file 6} \ No newline at end of file
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index d81f4543..01879bac 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -6,10 +6,11 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 FileIo = require("js/io/system/fileio").FileIo, 11 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo; 12 ProjectIo = require("js/io/system/projectio").ProjectIo,
13 TemplateCreator = require("node_modules/tools/template-creator").TemplateCreator;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14// 15//
15exports.IoMediator = Montage.create(Component, { 16exports.IoMediator = Montage.create(Component, {
@@ -369,7 +370,7 @@ exports.IoMediator = Montage.create(Component, {
369 } 370 }
370 } 371 }
371 // 372 //
372 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag; 373 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag;
373 // 374 //
374 for (var i in scripts) { 375 for (var i in scripts) {
375 if (scripts[i].getAttribute) { 376 if (scripts[i].getAttribute) {
@@ -385,6 +386,12 @@ exports.IoMediator = Montage.create(Component, {
385 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { 386 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
386 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags 387 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
387 } 388 }
389 if (scripts[i].getAttribute('type') !== 'text/montage-serialization') {
390 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
391 }
392 if (scripts[i].getAttribute('data-mjs-lib') !== null) {
393 mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
394 }
388 } 395 }
389 } 396 }
390 // 397 //
@@ -451,6 +458,59 @@ function loadWebGL (e) {\n\
451 //Setting string in tag 458 //Setting string in tag
452 webgltag.innerHTML = json; 459 webgltag.innerHTML = json;
453 } 460 }
461
462
463
464
465 //
466 var mjsCounter = 0, mjsComponents = [], temp = TemplateCreator.create();
467 for (var m in template.mjs) {
468 mjsComponents.push(template.mjs[m]);
469 mjsCounter++;
470 }
471
472// console.log(mjsComponents);
473
474 //console.log(TemplateCreator.)
475
476 if (template.mjs && mjsCounter > 0) {
477 var mjsDirName, mjsVersion,
478 mjscode = temp.initWithHeadAndBodyElements(template.document.content.document.documentElement.head, template.document.content.document.documentElement.body, mjsComponents)._ownerSerialization;
479 //Copy Montage library if needed
480 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
481 //Checking for Montage library to be available
482 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
483 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
484 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
485 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, mjsDirName);
486 //TODO: Fix to allow no overwrite
487 var packjson = this.application.ninja.coreIoApi.createFile({uri: template.document.root+'package.json', contents: '{"mappings": {"montage": "'+mjsDirName+'/"}}'});
488 } else {
489 //TODO: Error handle no available library to copy
490 }
491 }
492 //
493 if (!mjslibtag) {
494 mjslibtag = template.document.content.document.createElement('script');
495 mjslibtag.setAttribute('type', 'text/javascript');
496 mjslibtag.setAttribute('src', mjsDirName+'/montage.js');
497 mjslibtag.setAttribute('data-mjs-lib', 'true');
498 template.document.content.document.head.appendChild(mjslibtag);
499 }
500 //
501 if (!mjstag) {
502 mjstag = template.document.content.document.createElement('script');
503 mjstag.setAttribute('type', 'text/montage-serialization');
504 template.document.content.document.head.appendChild(mjstag);
505 }
506 //
507 mjstag.innerHTML = mjscode;
508 }
509
510
511
512
513
454 //Cleaning URLs from HTML 514 //Cleaning URLs from HTML
455 var cleanHTML = template.document.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); 515 var cleanHTML = template.document.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this));
456 // 516 //
diff --git a/node_modules/descriptor.json b/node_modules/descriptor.json
index c460066c..d5bb81f3 100644
--- a/node_modules/descriptor.json
+++ b/node_modules/descriptor.json
@@ -169,6 +169,7 @@
169 "ui/component.js", 169 "ui/component.js",
170 "ui/composer/composer.js", 170 "ui/composer/composer.js",
171 "ui/composer/long-press-composer.js", 171 "ui/composer/long-press-composer.js",
172 "ui/composer/press-composer.js",
172 "ui/composer/swipe-composer.js", 173 "ui/composer/swipe-composer.js",
173 "ui/composer/translate-composer.js", 174 "ui/composer/translate-composer.js",
174 "ui/condition.reel/condition.js", 175 "ui/condition.reel/condition.js",
@@ -219,21 +220,19 @@
219 "ui/popup/popup.reel/popup.css", 220 "ui/popup/popup.reel/popup.css",
220 "ui/popup/popup.reel/popup.html", 221 "ui/popup/popup.reel/popup.html",
221 "ui/popup/popup.reel/popup.js", 222 "ui/popup/popup.reel/popup.js",
222 "ui/progress.reel/progress.css",
223 "ui/progress.reel/progress.html",
224 "ui/progress.reel/progress.js", 223 "ui/progress.reel/progress.js",
225 "ui/progress.reel/rule.png",
226 "ui/progress.reel/scroll.png",
227 "ui/radio-button.reel/radio-button.js", 224 "ui/radio-button.reel/radio-button.js",
228 "ui/range-input.reel/range-input.js", 225 "ui/range-input.reel/range-input.js",
229 "ui/repetition.reel/repetition.js", 226 "ui/repetition.reel/repetition.js",
230 "ui/scroll-bars.reel/scroll-bars.html", 227 "ui/scroll-bars.reel/scroll-bars.html",
231 "ui/scroll-bars.reel/scroll-bars.js", 228 "ui/scroll-bars.reel/scroll-bars.js",
232 "ui/scroll.js",
233 "ui/scroller.reel/scroller.html", 229 "ui/scroller.reel/scroller.html",
234 "ui/scroller.reel/scroller.js", 230 "ui/scroller.reel/scroller.js",
235 "ui/scrollview.reel/scrollview.js", 231 "ui/scrollview.reel/scrollview.js",
236 "ui/select-input.reel/select-input.js", 232 "ui/select-input.reel/select-input.js",
233 "ui/skeleton/range-input.reel/range-input.css",
234 "ui/skeleton/range-input.reel/range-input.html",
235 "ui/skeleton/range-input.reel/range-input.js",
237 "ui/slot.reel/slot.js", 236 "ui/slot.reel/slot.js",
238 "ui/substitution.reel/substitution.js", 237 "ui/substitution.reel/substitution.js",
239 "ui/tabs.reel/tabs.css", 238 "ui/tabs.reel/tabs.css",
diff --git a/node_modules/tools/template-creator.js b/node_modules/tools/template-creator.js
index 6b50cc1e..ba4cdc7a 100644
--- a/node_modules/tools/template-creator.js
+++ b/node_modules/tools/template-creator.js
@@ -31,10 +31,10 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
31 }, 31 },
32 32
33 initWithHeadAndBodyElements: { 33 initWithHeadAndBodyElements: {
34 value: function(head, body, montageJsPath) { 34 value: function(head, body, components, montageJsPath) {
35 var serializer = this.serializer, 35 var serializer = this.serializer,
36 objects = {}, 36 objects = {},
37 components = {}, 37 //components = {},
38 doc, 38 doc,
39 script, 39 script,
40 self = this; 40 self = this;
@@ -42,7 +42,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
42 this._objectNamesIndex = {}; 42 this._objectNamesIndex = {};