Skip to content

Commit

Permalink
Merge pull request #13145 from emberjs/dynamic-tag-name
Browse files Browse the repository at this point in the history
[Glimmer 2] Add support for dynamic `tagName`
  • Loading branch information
chancancode committed Mar 21, 2016
2 parents e444625 + a3e278e commit f3eea41
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"express": "^4.5.0",
"finalhandler": "^0.4.0",
"github": "^0.2.3",
"glimmer-engine": "tildeio/glimmer#9dff505",
"glimmer-engine": "tildeio/glimmer#536bed2",
"glob": "^5.0.13",
"htmlbars": "0.14.16",
"mocha": "^2.4.5",
Expand Down
12 changes: 11 additions & 1 deletion packages/ember-glimmer/lib/components/curly-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ const MANAGER = new CurlyComponentManager();
import { ComponentDefinition, ValueReference } from 'glimmer-runtime';
import Component from '../ember-views/component';

function tagName(vm) {
let { tagName } = vm.dynamicScope().view;

if (tagName === '') {
throw new Error('Not implemented: fragments (`tagName: ""`)');
}

return new ValueReference(tagName || 'div');
}

function elementId(vm) {
let component = vm.dynamicScope().view;
return new ValueReference(component.elementId);
Expand All @@ -90,7 +100,7 @@ export class CurlyComponentDefinition extends ComponentDefinition {

compile(builder) {
builder.wrapLayout(this.template.asLayout());
builder.tag.static('div');
builder.tag.dynamic(tagName);
builder.attrs.dynamic('id', elementId);
builder.attrs.static('class', 'ember-view');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ moduleFor('Components test: curly components', class extends RenderingTest {
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

['@test it can have a custom tagName']() {
let FooBarComponent = Component.extend({
tagName: 'foo-bar'
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' });

this.render('{{foo-bar}}');

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });

this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });
}

['@test it can have a custom tagName set in the constructor']() {
let FooBarComponent = Component.extend({
init() {
this._super();
this.tagName = 'foo-bar';
}
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' });

this.render('{{foo-bar}}');

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });

this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });
}

['@test it can have a custom tagName from the invocation']() {
this.registerComponent('foo-bar', { template: 'hello' });

this.render('{{foo-bar tagName="foo-bar"}}');

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });

this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' });
}

['@test it has an element']() {
let instance;

Expand Down

0 comments on commit f3eea41

Please sign in to comment.