Skip to content

Commit

Permalink
Changes SoyComponent to stop creating surfaces for private templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mairatma committed Jul 6, 2015
1 parent a18fd6f commit b252ea8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/soy/SoyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
15 changes: 8 additions & 7 deletions test/src/soy/SoyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/src/soy/assets/CustomTestComponent.soy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/**
*/
{template .content}
{call .title}
{param title: 'My Title' /}
{/call}
{delcall CustomTestComponent.header data="all" /}
{delcall CustomTestComponent.footer data="all" /}
{/template}
Expand All @@ -21,6 +24,13 @@
{$footerContent}
{/template}

/**
* @param title
*/
{template .title private="true"}
{$title}
{/template}

/**
* @param? elementContent
* @param? elementClasses
Expand Down

0 comments on commit b252ea8

Please sign in to comment.