Forked from danlourenco/components.hello-component.js
Created
August 23, 2016 14:02
-
-
Save kdimatteo/2086d4b0860ab49bc8de8852eef45324 to your computer and use it in GitHub Desktop.
component interpolation within handlebars template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['ember-component'] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['ember-component'] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { computed, get } = Ember; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
display: ['<table border="1" cellpadding="0" cellspacing="0" width="100%"><tbody>↵<tr>↵<td width="50%"><b>QUESTIONS</b></td>↵<td width="50%"><b>RESPONSES</b></td>↵</tr>↵↵<tr>↵<td width="50%">Blue is your favorite color?</td>↵<td width="50%">', | |
{componentName: "my-component"}, | |
'</td>↵</tr>↵↵<tr><td width="50%">Clowns are evil?</td><td width="50%">', | |
{componentName: "hello-component"}, | |
'</td>↵</tr>↵↵</tbody></table>↵↵<p> ' | |
], | |
compiledHTML: Ember.computed('display', function(){ | |
let display = get(this, 'display'); | |
let domString = ''; | |
display.forEach(function(el) { | |
if (typeof el === 'string') { | |
domString += el; | |
} else { | |
domString += '<span class="replace-with-component"></span>'; | |
} | |
}); | |
return domString; | |
}), | |
componentsToRender: Ember.computed('display', function() { | |
let display = Ember.get(this, 'display'); | |
let componentsToRender = []; | |
display.forEach(function(item) { | |
if (item.componentName) { | |
componentsToRender.push(item); | |
} | |
}); | |
return componentsToRender; | |
}), | |
worksheetHasTableLayout: computed('compiledHTML', function() { | |
let html = get(this, 'compiledHTML'); | |
return html.indexOf('<table') !== -1; | |
}), | |
// can we programatically render all components in componentsToRender array into DOM elements with a class of 'js-componentInsertion' ? | |
init() { | |
this._super(...arguments); | |
this.scheduleMoveComponents(); | |
}, | |
didInsertElement: function() { | |
this.scheduleMoveComponents(); | |
}, | |
scheduleMoveComponents:(function(){ | |
var self = this; | |
Ember.run.schedule('afterRender', function() { | |
self._moveComponents(); | |
}); | |
}).observes('display'), | |
_moveComponents: function() { | |
if (!Ember.get(this, 'worksheetHasTableLayout')) { | |
return; | |
} | |
let componentSlots = Ember.$('.replace-with-component'); | |
let components = Ember.$('.ember-component'); | |
componentSlots.each(function(item) { | |
Ember.$(this).replaceWith(components[item]); | |
}); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export function injector(params/*, hash*/) { | |
console.log(params); | |
return params; | |
} | |
export default Ember.Helper.helper(injector); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.ember-component { | |
background: lightblue; | |
border: 1px solid; | |
border-radius: 2px; | |
margin: 2px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.4", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.7.0", | |
"ember-data": "2.7.0", | |
"ember-template-compiler": "2.7.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment