From fda7b595c96d99177fdd93de8da9030348a3f8fb Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 18 Mar 2012 12:34:29 -0700 Subject: Temp I/O functionality for M-JS components Added the ability to save montages component serialization from Ninja. Very rough, but functional. --- js/document/html-document.js | 4 +- js/io/system/ninjalibrary.json | 4 +- js/mediators/io-mediator.js | 70 +++++++++++++++++++++++++++++++--- node_modules/descriptor.json | 9 ++--- node_modules/tools/template-creator.js | 12 +++--- 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, { } } } - return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; + return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; } else if (this.currentView === "code"){ //TODO: Would this get call when we are in code of HTML? } else { @@ -928,7 +928,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } } - return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; + return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; } else if (this.currentView === "code"){ //TODO: Would this get call when we are in code of HTML? } 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 @@ { "libraries": [ - {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.6.0.0"}, - {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.1.0"} + {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.7.0.0"}, + {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.1.1"} ] } \ 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 //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - FileIo = require("js/io/system/fileio").FileIo, - ProjectIo = require("js/io/system/projectio").ProjectIo; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + FileIo = require("js/io/system/fileio").FileIo, + ProjectIo = require("js/io/system/projectio").ProjectIo, + TemplateCreator = require("node_modules/tools/template-creator").TemplateCreator; //////////////////////////////////////////////////////////////////////// // exports.IoMediator = Montage.create(Component, { @@ -369,7 +370,7 @@ exports.IoMediator = Montage.create(Component, { } } // - var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag; + var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; // for (var i in scripts) { if (scripts[i].getAttribute) { @@ -385,6 +386,12 @@ exports.IoMediator = Montage.create(Component, { if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags } + if (scripts[i].getAttribute('type') !== 'text/montage-serialization') { + mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } + if (scripts[i].getAttribute('data-mjs-lib') !== null) { + mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } } } // @@ -451,6 +458,59 @@ function loadWebGL (e) {\n\ //Setting string in tag webgltag.innerHTML = json; } + + + + + // + var mjsCounter = 0, mjsComponents = [], temp = TemplateCreator.create(); + for (var m in template.mjs) { + mjsComponents.push(template.mjs[m]); + mjsCounter++; + } + +// console.log(mjsComponents); + + //console.log(TemplateCreator.) + + if (template.mjs && mjsCounter > 0) { + var mjsDirName, mjsVersion, + mjscode = temp.initWithHeadAndBodyElements(template.document.content.document.documentElement.head, template.document.content.document.documentElement.body, mjsComponents)._ownerSerialization; + //Copy Montage library if needed + for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { + //Checking for Montage library to be available + if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { + mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); + mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; + this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, mjsDirName); + //TODO: Fix to allow no overwrite + var packjson = this.application.ninja.coreIoApi.createFile({uri: template.document.root+'package.json', contents: '{"mappings": {"montage": "'+mjsDirName+'/"}}'}); + } else { + //TODO: Error handle no available library to copy + } + } + // + if (!mjslibtag) { + mjslibtag = template.document.content.document.createElement('script'); + mjslibtag.setAttribute('type', 'text/javascript'); + mjslibtag.setAttribute('src', mjsDirName+'/montage.js'); + mjslibtag.setAttribute('data-mjs-lib', 'true'); + template.document.content.document.head.appendChild(mjslibtag); + } + // + if (!mjstag) { + mjstag = template.document.content.document.createElement('script'); + mjstag.setAttribute('type', 'text/montage-serialization'); + template.document.content.document.head.appendChild(mjstag); + } + // + mjstag.innerHTML = mjscode; + } + + + + + //Cleaning URLs from HTML 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)); // 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 @@ "ui/component.js", "ui/composer/composer.js", "ui/composer/long-press-composer.js", + "ui/composer/press-composer.js", "ui/composer/swipe-composer.js", "ui/composer/translate-composer.js", "ui/condition.reel/condition.js", @@ -219,21 +220,19 @@ "ui/popup/popup.reel/popup.css", "ui/popup/popup.reel/popup.html", "ui/popup/popup.reel/popup.js", - "ui/progress.reel/progress.css", - "ui/progress.reel/progress.html", "ui/progress.reel/progress.js", - "ui/progress.reel/rule.png", - "ui/progress.reel/scroll.png", "ui/radio-button.reel/radio-button.js", "ui/range-input.reel/range-input.js", "ui/repetition.reel/repetition.js", "ui/scroll-bars.reel/scroll-bars.html", "ui/scroll-bars.reel/scroll-bars.js", - "ui/scroll.js", "ui/scroller.reel/scroller.html", "ui/scroller.reel/scroller.js", "ui/scrollview.reel/scrollview.js", "ui/select-input.reel/select-input.js", + "ui/skeleton/range-input.reel/range-input.css", + "ui/skeleton/range-input.reel/range-input.html", + "ui/skeleton/range-input.reel/range-input.js", "ui/slot.reel/slot.js", "ui/substitution.reel/substitution.js", "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 }, initWithHeadAndBodyElements: { - value: function(head, body, montageJsPath) { + value: function(head, body, components, montageJsPath) { var serializer = this.serializer, objects = {}, - components = {}, + //components = {}, doc, script, self = this; @@ -42,7 +42,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le this._objectNamesIndex = {}; doc = this._document = document.implementation.createHTMLDocument(""); - function copyNode(sourceNode, targetNode, isRootNode) { + /* +function copyNode(sourceNode, targetNode, isRootNode) { var childNodes = sourceNode.childNodes, childNode, targetChildNode, @@ -54,7 +55,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le label = self._generateLabelForComponent(component); targetNode.setAttribute("id", label); component._element = targetNode; - components[label] = component; + //components[label] = component; } else { for (var i = 0; (childNode = childNodes[i]); i++) { targetChildNode = targetNode.appendChild(childNode.cloneNode(false)); @@ -62,6 +63,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le } } } +*/ if (head) { doc.head.innerHTML = head.innerHTML; @@ -83,7 +85,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le doc.head.insertBefore(doc.createTextNode("\n "), doc.head.firstChild); } - copyNode(body, this._document.body, true); + //copyNode(body, this._document.body, true); this._ownerSerialization = serializer.serialize(components); this._externalObjects = serializer.getExternalObjects(); -- cgit v1.2.3