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/tools')
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
From 5de553a1b3bdd8783ab6ce017ae70369ad92a890 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Wed, 16 May 2012 11:37:05 -0700
Subject: Fixing preview bug
Also setting up for Montage component serialization.
---
node_modules/tools/package.json | 14 ++++++++++++++
node_modules/tools/template/template-creator.js | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100755 node_modules/tools/package.json
(limited to 'node_modules/tools')
diff --git a/node_modules/tools/package.json b/node_modules/tools/package.json
new file mode 100755
index 00000000..5d830af3
--- /dev/null
+++ b/node_modules/tools/package.json
@@ -0,0 +1,14 @@
+
+{
+ "name": "tools",
+ "version": "0.1.0",
+ "description": "Montage Tools",
+ "main": "tools",
+ "mappings": {
+ "montage" : "../montage/"
+ },
+ "dependency": {
+ "montage" : "0.8"
+ }
+
+}
\ No newline at end of file
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js
index 1cd65ddd..374353f0 100755
--- a/node_modules/tools/template/template-creator.js
+++ b/node_modules/tools/template/template-creator.js
@@ -39,7 +39,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
script,
self = this;
- this._objectNamesIndex = {};
+ this._componentNamesIndex = {};
doc = this._document = document.implementation.createHTMLDocument("");
function copyNode(sourceNode, targetNode, isRootNode) {
--
cgit v1.2.3
From 75a01802f73e791b082229f065eeb3df6a48a962 Mon Sep 17 00:00:00 2001
From: António Afonso
Date: Wed, 30 May 2012 10:17:49 -0700
Subject: Avoid duplicate labels in template creator
This is the fix for Motorola-Mobility/montage#649---
node_modules/tools/template/template-creator.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
(limited to 'node_modules/tools')
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js
index 374353f0..dc6b1190 100755
--- a/node_modules/tools/template/template-creator.js
+++ b/node_modules/tools/template/template-creator.js
@@ -51,8 +51,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
component = isRootNode ? null : sourceNode.controller;
if (component) {
- label = self._generateLabelForComponent(component);
targetNode.setAttribute("id", label);
+ label = self._generateLabelForComponent(component, Object.keys(components));
component._element = targetNode;
components[label] = component;
} else {
@@ -94,8 +94,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
_componentNamesIndex: {
value: null
},
-
- _generateLabelForComponent: {value: function(component) {
+
+ _generateLabelForComponent: {value: function(component, labels) {
var componentInfo = Montage.getInfoForObject(component),
componentLabel = componentInfo.label,
componentName,
@@ -105,8 +105,11 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
return componentLabel;
} else {
componentName = componentInfo.objectName.toLowerCase();
- index = this._componentNamesIndex[componentName] || 1;
- this._componentNamesIndex[componentName] = index + 1;
+ do {
+ index = this._componentNamesIndex[componentName] || 1;
+ this._componentNamesIndex[componentName] = index + 1;
+ } while (labels.indexOf(componentName+index) >= 0);
+
return componentName + index;
}
}},
--
cgit v1.2.3
From e6dbd73e80ac47ae9bfdfdb5bef3263b24a36603 Mon Sep 17 00:00:00 2001
From: António Afonso
Date: Wed, 30 May 2012 10:34:45 -0700
Subject: Stop adding ids to elements in template creator
This is the fix for Motorola-Mobility/montage#648
---
node_modules/tools/template/template-creator.js | 1 -
1 file changed, 1 deletion(-)
(limited to 'node_modules/tools')
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js
index dc6b1190..4ba1b443 100755
--- a/node_modules/tools/template/template-creator.js
+++ b/node_modules/tools/template/template-creator.js
@@ -51,7 +51,6 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
component = isRootNode ? null : sourceNode.controller;
if (component) {
- targetNode.setAttribute("id", label);
label = self._generateLabelForComponent(component, Object.keys(components));
component._element = targetNode;
components[label] = component;
--
cgit v1.2.3
From 87a5999ecd9e7d84d21fd8c712944cd9408c3aa0 Mon Sep 17 00:00:00 2001
From: António Afonso
Date: Wed, 30 May 2012 10:36:59 -0700
Subject: Stop serializing the child components of the top components are not
serialized
We just removed them before serializing and add them again afterwards.---
node_modules/tools/template/template-creator.js | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'node_modules/tools')
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js
index 4ba1b443..01a2518b 100755
--- a/node_modules/tools/template/template-creator.js
+++ b/node_modules/tools/template/template-creator.js
@@ -35,6 +35,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
var serializer = this.serializer,
objects = {},
components = {},
+ componentsChildComponents = {},
doc,
script,
self = this;
@@ -54,6 +55,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
label = self._generateLabelForComponent(component, Object.keys(components));
component._element = targetNode;
components[label] = component;
+ componentsChildComponents[label] = component.childComponents;
+ delete component.childComponents;
} else {
for (var i = 0; (childNode = childNodes[i]); i++) {
targetChildNode = targetNode.appendChild(childNode.cloneNode(false));
@@ -84,6 +87,10 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
copyNode(body, this._document.body, true);
this._ownerSerialization = serializer.serialize(components);
+ for (var label in components) {
+ components[label].childComponents = componentsChildComponents[label];
+ }
+ components = componentsChildComponents = null;
this._externalObjects = serializer.getExternalObjects();
return this;
--
cgit v1.2.3
From 78c80a68083ed8ad573898de215fb723b0546d32 Mon Sep 17 00:00:00 2001
From: António Afonso
Date: Wed, 30 May 2012 10:37:38 -0700
Subject: Initialize an internal Template variable in TemplateCreator
---
node_modules/tools/template/template-creator.js | 1 +
1 file changed, 1 insertion(+)
(limited to 'node_modules/tools')
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js
index 01a2518b..c5d3cffd 100755
--- a/node_modules/tools/template/template-creator.js
+++ b/node_modules/tools/template/template-creator.js
@@ -41,6 +41,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
self = this;
this._componentNamesIndex = {};
+ this._objectNamesIndex = {};
doc = this._document = document.implementation.createHTMLDocument("");
function copyNode(sourceNode, targetNode, isRootNode) {
--
cgit v1.2.3