Skip to content

Instantly share code, notes, and snippets.

@tbrd
Created March 2, 2014 17:13
Show Gist options
  • Save tbrd/9309836 to your computer and use it in GitHub Desktop.
Save tbrd/9309836 to your computer and use it in GitHub Desktop.
Hashtags component with internal template definition
define(function (require) {
'use strict';
/**
* Module dependencies
*/
var defineComponent = require('flight/lib/component');
var withHogan = require('flight-hogan/lib/with_hogan');
/**
* Module exports
*/
return defineComponent(hashtags, withHogan);
/**
* Module function
*/
function hashtags() {
this.defaultAttrs({
template:
'<table class="js-hashtags">' +
'<thead>' +
'<tr>' +
'<th>Hashtag</th>' +
'<th>Frequency</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'{{#hashtags}}' +
'<tr>' +
'<td>#{{text}}</td>' +
'<td>{{frequency}}</td>' +
'</tr>' +
'{{/hashtags}}' +
'</tbody>' +
'</table>'
});
this.after('initialize', function () {
this.on(document, 'data-hashtags', this.handleHashtagData);
});
this.handleHashtagData = function (event, data) {
var html = this.renderTemplate({
template: this.attr.template,
renderParams: data
});
this.$node.html(html);
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment