Skip to content

Instantly share code, notes, and snippets.

@rheaton
Last active October 6, 2015 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rheaton/3062378 to your computer and use it in GitHub Desktop.
Save rheaton/3062378 to your computer and use it in GitHub Desktop.
emerson up and running in rails >= 3.2
// .... require all the things you need
// Vendored requires
//= require jquery
//= require underscore
//= require emerson
// Application requires
//= require base
//= require_tree ./lib/traits
//= require_tree ./lib/views
(function($, window) {
$(window).load(function() {
Emerson.init();
});
})(jQuery, this);
gem 'emerson'
(function($, define) {
var trait = define('alerter', {
initialize : function initialize() {
console.log("initializing trait!");
},
subscribe : {
'mouseout' : function handler(e) {
this.alertMethod();
}
}
});
trait.extend({
alertMethod : function alertMethod() {
alert("you moused out");
}
});
})(Emerson.base, Emerson.trait);
<p>
Here is some text.
<span data-traits='alerter'>I should alert when you mouse out!</span>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment