From b252ea81b5e1e32742b9b3737d03512b1ec1e298 Mon Sep 17 00:00:00 2001 From: Maira Bello Date: Mon, 6 Jul 2015 14:04:18 -0300 Subject: [PATCH] Changes SoyComponent to stop creating surfaces for private templates --- package.json | 2 +- src/soy/SoyComponent.js | 4 +++- test/src/soy/SoyComponent.js | 15 ++++++++------- test/src/soy/assets/CustomTestComponent.soy | 10 ++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 6c1fe59c..88c64691 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "devDependencies": { "chai": "^3.0.0", "gulp": "^3.9.0", - "gulp-metal": "^0.1.5", + "gulp-metal": "^0.2.2", "isparta": "^3.0.3", "karma": "^0.12.31", "karma-babel-preprocessor": "^5.1.0", diff --git a/src/soy/SoyComponent.js b/src/soy/SoyComponent.js index ac780126..88a41229 100644 --- a/src/soy/SoyComponent.js +++ b/src/soy/SoyComponent.js @@ -65,7 +65,9 @@ class SoyComponent extends Component { var templateNames = Object.keys(templates); for (var i = 0; i < templateNames.length; i++) { var templateName = templateNames[i]; - if (templateName !== 'content' && templateName.substr(0, 13) !== '__deltemplate') { + if (templateName !== 'content' && + templateName.substr(0, 13) !== '__deltemplate' && + templates[templateName].params) { var surface = this.getSurface(templateName); if (!surface) { this.addSurface(templateName, { diff --git a/test/src/soy/SoyComponent.js b/test/src/soy/SoyComponent.js index 01c90493..cb00dade 100644 --- a/test/src/soy/SoyComponent.js +++ b/test/src/soy/SoyComponent.js @@ -37,11 +37,12 @@ describe('SoyComponent', function() { }); custom.render(); - assert.strictEqual(2, custom.element.childNodes.length); - assert.strictEqual(custom.getSurfaceElement('header'), custom.element.childNodes[0]); - assert.strictEqual('My Header', custom.element.childNodes[0].innerHTML); - assert.strictEqual(custom.getSurfaceElement('footer'), custom.element.childNodes[1]); - assert.strictEqual('My Footer', custom.element.childNodes[1].innerHTML); + assert.strictEqual(3, custom.element.childNodes.length); + assert.strictEqual('My Title', custom.element.childNodes[0].textContent); + assert.strictEqual(custom.getSurfaceElement('header'), custom.element.childNodes[1]); + assert.strictEqual('My Header', custom.element.childNodes[1].innerHTML); + assert.strictEqual(custom.getSurfaceElement('footer'), custom.element.childNodes[2]); + assert.strictEqual('My Footer', custom.element.childNodes[2].innerHTML); }); it('should render element tag according to its template when defined', function() { @@ -104,7 +105,7 @@ describe('SoyComponent', function() { }); describe('Surfaces', function() { - it('should automatically create surfaces for a component\'s templates', function() { + it('should automatically create surfaces for a component\'s non private templates', function() { var CustomTestComponent = createCustomTestComponentClass(); var custom = new CustomTestComponent(); @@ -254,7 +255,7 @@ describe('SoyComponent', function() { var child = custom.components.nestedMyChild0; assert.strictEqual(childPlaceholder, child.element); - assert.strictEqual(2, childPlaceholder.childNodes.length); + assert.strictEqual(3, childPlaceholder.childNodes.length); }); it('should update rendered child component', function(done) { diff --git a/test/src/soy/assets/CustomTestComponent.soy b/test/src/soy/assets/CustomTestComponent.soy index 30715667..1ced9217 100644 --- a/test/src/soy/assets/CustomTestComponent.soy +++ b/test/src/soy/assets/CustomTestComponent.soy @@ -3,6 +3,9 @@ /** */ {template .content} + {call .title} + {param title: 'My Title' /} + {/call} {delcall CustomTestComponent.header data="all" /} {delcall CustomTestComponent.footer data="all" /} {/template} @@ -21,6 +24,13 @@ {$footerContent} {/template} +/** + * @param title + */ +{template .title private="true"} + {$title} +{/template} + /** * @param? elementContent * @param? elementClasses