Skip to content

Instantly share code, notes, and snippets.

@balinterdi balinterdi/html-helper.js
Last active Dec 21, 2015

What would you like to do?
Resources for the Ember.js workshop at Eurucamp 2013
Ember.Handlebars.helper('html', function(tweet, options) {
var replaceUrls = function(text, urlData) {
var start = urlData.indices[0];
var end = urlData.indices[1];
return text.slice(0, start) + '<a href="' + urlData.expanded_url + '">' + urlData.display_url + '</a>' + text.slice(end);
// Essentially there is no way to extract urls from RTs from the data Twitter provides
// so we might as well go simply matching urls in the text
var text = tweet.get('text').replace(/\n/g, '<br />');
var urlEntities = tweet.get('entities.urls');
var withUrls = text;
urlEntities.forEach(function(urlData) {
//FIXME: This breaks when there are multiple urls
withUrls = replaceUrls(text, urlData);
var mediaEntities = tweet.get('') || [];
mediaEntities.forEach(function(urlData) {
withUrls = replaceUrls(withUrls, urlData);
return new Handlebars.SafeString(withUrls);

Resources for the example app during the workshop


Environment variables


Data (Persistence) libraries

Email list

There is an email list to receive updates on the Eurucamp example development and tips & best practices on Ember.js development. Sign up here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.