From 3811f72f8cd8caaa2d13fa695b918f25facb85c5 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 9 May 2012 16:28:13 -0700 Subject: Preliminary Montage Template Cleanup The template creator is currently not returning serializing code, but does clean the document. Need to investigate reason why, currently all components are removed on save. --- node_modules/tools/template-creator.js | 117 ------------------------ node_modules/tools/template/template-creator.js | 113 +++++++++++++++++++++++ 2 files changed, 113 insertions(+), 117 deletions(-) delete mode 100644 node_modules/tools/template-creator.js create mode 100755 node_modules/tools/template/template-creator.js (limited to 'node_modules') diff --git a/node_modules/tools/template-creator.js b/node_modules/tools/template-creator.js deleted file mode 100644 index e312cd32..00000000 --- a/node_modules/tools/template-creator.js +++ /dev/null @@ -1,117 +0,0 @@ -/* - This file contains proprietary software owned by Motorola Mobility, Inc.
- No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
- (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ -/** - @module montage/tools/template/template-creator - @requires montage/ui/template -*/ - -exports = typeof exports !== "undefined" ? exports : {}; - -var Montage = require("montage/core/core").Montage; -var Template = require("montage/ui/template").Template; - -/** - @class module:montage/tools/template/template-creator.TemplateCreator - @extends module:montage/ui/template.Template -*/ -var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @lends module:montage/tools/template/template-creator.TemplateCreator# */ { - initWithDocument: { - value: function(doc, montageJsPath) { - return this.initWithHeadAndBodyElements(doc.head, doc.body, montageJsPath); - } - }, - - initWithBodyElement: { - value: function(body, montageJsPath) { - return this.initWithHeadAndBodyElements(null, body, montageJsPath); - } - }, - - initWithHeadAndBodyElements: { - value: function(head, body, components, montageJsPath) { - var serializer = this.serializer, - objects = {}, - //components = {}, - doc, - script, - self = this; - - this._objectNamesIndex = {}; - //doc = this._document = document.implementation.createHTMLDocument(""); - - /* -function copyNode(sourceNode, targetNode, isRootNode) { - var childNodes = sourceNode.childNodes, - childNode, - targetChildNode, - label, - script, - component = isRootNode ? null : sourceNode.controller; - - if (component) { - label = self._generateLabelForComponent(component); - targetNode.setAttribute("id", label); - component._element = targetNode; - //components[label] = component; - } else { - for (var i = 0; (childNode = childNodes[i]); i++) { - targetChildNode = targetNode.appendChild(childNode.cloneNode(false)); - copyNode(childNode, targetChildNode); - } - } - } -*/ - - /* -if (head) { - doc.head.innerHTML = head.innerHTML; - } - if (montageJsPath) { - script = doc.createElement("script"); - script.setAttribute("src", montageJsPath); - doc.head.appendChild(script); - doc.head.insertBefore(doc.createTextNode("\n "), script); - } - - // try to make things look nice... - var html = doc.documentElement; - html.insertBefore(doc.createTextNode("\n"), doc.head); - html.insertBefore(doc.createTextNode("\n"), doc.body); - html.appendChild(doc.createTextNode("\n")); - if (!head) { - // the first child is the title - doc.head.insertBefore(doc.createTextNode("\n "), doc.head.firstChild); - } -*/ - - //copyNode(body, this._document.body, true); - this._ownerSerialization = serializer.serialize(components); - this._externalObjects = serializer.getExternalObjects(); - - return this; - } - }, - - _componentNamesIndex: { - value: null - }, - - _generateLabelForComponent: {value: function(component) { - var componentInfo = Montage.getInfoForObject(component), - componentLabel = componentInfo.label, - componentName, - index; - - if (componentLabel) { - return componentLabel; - } else { - componentName = componentInfo.objectName.toLowerCase(); - index = this._componentNamesIndex[componentName] || 1; - this._componentNamesIndex[componentName] = index + 1; - return componentName + index; - } - }}, -}); \ No newline at end of file diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js new file mode 100755 index 00000000..1cd65ddd --- /dev/null +++ b/node_modules/tools/template/template-creator.js @@ -0,0 +1,113 @@ +/* + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ +/** + @module montage/tools/template/template-creator + @requires montage/ui/template +*/ + +exports = typeof exports !== "undefined" ? exports : {}; + +var Montage = require("montage/core/core").Montage; +var Template = require("montage/ui/template").Template; + +/** + @class module:montage/tools/template/template-creator.TemplateCreator + @extends module:montage/ui/template.Template +*/ +var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @lends module:montage/tools/template/template-creator.TemplateCreator# */ { + initWithDocument: { + value: function(doc, montageJsPath) { + return this.initWithHeadAndBodyElements(doc.head, doc.body, montageJsPath); + } + }, + + initWithBodyElement: { + value: function(body, montageJsPath) { + return this.initWithHeadAndBodyElements(null, body, montageJsPath); + } + }, + + initWithHeadAndBodyElements: { + value: function(head, body, montageJsPath) { + var serializer = this.serializer, + objects = {}, + components = {}, + doc, + script, + self = this; + + this._objectNamesIndex = {}; + doc = this._document = document.implementation.createHTMLDocument(""); + + function copyNode(sourceNode, targetNode, isRootNode) { + var childNodes = sourceNode.childNodes, + childNode, + targetChildNode, + label, + script, + component = isRootNode ? null : sourceNode.controller; + + if (component) { + label = self._generateLabelForComponent(component); + targetNode.setAttribute("id", label); + component._element = targetNode; + components[label] = component; + } else { + for (var i = 0; (childNode = childNodes[i]); i++) { + targetChildNode = targetNode.appendChild(childNode.cloneNode(false)); + copyNode(childNode, targetChildNode); + } + } + } + + if (head) { + doc.head.innerHTML = head.innerHTML; + } + if (montageJsPath) { + script = doc.createElement("script"); + script.setAttribute("src", montageJsPath); + doc.head.appendChild(script); + doc.head.insertBefore(doc.createTextNode("\n "), script); + } + + // try to make things look nice... + var html = doc.documentElement; + html.insertBefore(doc.createTextNode("\n"), doc.head); + html.insertBefore(doc.createTextNode("\n"), doc.body); + html.appendChild(doc.createTextNode("\n")); + if (!head) { + // the first child is the title + doc.head.insertBefore(doc.createTextNode("\n "), doc.head.firstChild); + } + + copyNode(body, this._document.body, true); + this._ownerSerialization = serializer.serialize(components); + this._externalObjects = serializer.getExternalObjects(); + + return this; + } + }, + + _componentNamesIndex: { + value: null + }, + + _generateLabelForComponent: {value: function(component) { + var componentInfo = Montage.getInfoForObject(component), + componentLabel = componentInfo.label, + componentName, + index; + + if (componentLabel) { + return componentLabel; + } else { + componentName = componentInfo.objectName.toLowerCase(); + index = this._componentNamesIndex[componentName] || 1; + this._componentNamesIndex[componentName] = index + 1; + return componentName + index; + } + }}, +}); \ No newline at end of file -- cgit v1.2.3