aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tools
diff options
context:
space:
mode:
authorAntónio Afonso2012-05-30 10:17:49 -0700
committerAntónio Afonso2012-05-30 10:17:49 -0700
commit75a01802f73e791b082229f065eeb3df6a48a962 (patch)
treea23e0c61605df6dfc140c113f96f6fcfe4da1448 /node_modules/tools
parent58e454c828abf0b64fa62120359bcd78a0d34ac4 (diff)
downloadninja-75a01802f73e791b082229f065eeb3df6a48a962.tar.gz
Avoid duplicate labels in template creator
This is the fix for Motorola-Mobility/montage#649
Diffstat (limited to 'node_modules/tools')
-rwxr-xr-xnode_modules/tools/template/template-creator.js13
1 files changed, 8 insertions, 5 deletions
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
51 component = isRootNode ? null : sourceNode.controller; 51 component = isRootNode ? null : sourceNode.controller;
52 52
53 if (component) { 53 if (component) {
54 label = self._generateLabelForComponent(component);
55 targetNode.setAttribute("id", label); 54 targetNode.setAttribute("id", label);
55 label = self._generateLabelForComponent(component, Object.keys(components));
56 component._element = targetNode; 56 component._element = targetNode;
57 components[label] = component; 57 components[label] = component;
58 } else { 58 } else {
@@ -94,8 +94,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
94 _componentNamesIndex: { 94 _componentNamesIndex: {
95 value: null 95 value: null
96 }, 96 },
97 97
98 _generateLabelForComponent: {value: function(component) { 98 _generateLabelForComponent: {value: function(component, labels) {
99 var componentInfo = Montage.getInfoForObject(component), 99 var componentInfo = Montage.getInfoForObject(component),
100 componentLabel = componentInfo.label, 100 componentLabel = componentInfo.label,
101 componentName, 101 componentName,
@@ -105,8 +105,11 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le
105 return componentLabel; 105 return componentLabel;
106 } else { 106 } else {
107 componentName = componentInfo.objectName.toLowerCase(); 107 componentName = componentInfo.objectName.toLowerCase();
108 index = this._componentNamesIndex[componentName] || 1; 108 do {
109 this._componentNamesIndex[componentName] = index + 1; 109 index = this._componentNamesIndex[componentName] || 1;
110 this._componentNamesIndex[componentName] = index + 1;
111 } while (labels.indexOf(componentName+index) >= 0);
112
110 return componentName + index; 113 return componentName + index;
111 } 114 }
112 }}, 115 }},