controller
controller copied to clipboard
An API for organizing your template logic.
Controller
An API for organizing your template logic.
Features
- Simplified syntax for defining template logic.
Contents
- Basic Usage
- API
- Tests
- Contributing
- Contributors
- License
Basic Usage
Controller is nothing more than an abstraction layer. Syntax sugar. Its only purpose is to help you tidy up your template logic. Okay...why?
Cleanliness. A few saved keystrokes on bigger chunks of logic. A little DRYer. Because I said so, okay?
Before Using Controller (356 Characters)
Template.exampleTemplate.onRendered(function(){
$(".widget").activate();
});
Template.exampleTemplate.onDestroyed(function(){
$(".widget").deactivate();
});
Template.exampleTemplate.helpers({
widgetHelper: function() {
return "some string of text";
}
});
Template.exampleTemplate.events({
'click .widget': function() {
magic();
}
});
Using Controller (334 Characters)
Controller('exampleTemplate', {
rendered: function() {
$(".widget").activate();
},
destroyed: function() {
$(".widget").deactivate();
},
helpers: {
widgetHelper: function() {
return "some string of text";
}
},
events: {
'click .widget': function() {
magic();
}
}
});
Possible reactions to this...
- "This is stupid!"
- "You'll never work in this town again!"
- "I went to MIT and I think this is useless! spits"
:cry: Buh. Here. Better? Thought that'd do the trick.
API
Controller comes with support for all of Meteor's standard template methods:
Controller{string} templateName{object} actions{function} created{function} rendered{function} destroyed{object} helpers{object} events
Full API usage:
Controller('myTemplate', {
created: function() {
// Stuff to do on created.
},
rendered: function() {
// Stuff to do on rendered.
},
destroyed: function() {
// Stuff to do on destroyed.
},
helpers: {
myHelper: function() {
// Put something on the template.
}
},
events: {
'click .something': function() {
// Do something on click.
}
}
});
Easy peasy.
Tests
Controller comes with a small suite of TinyTest-based tests to ensure that all of your logic makes it to the dark side safely. To run the tests:
- Install the TinyTest package
meteor add tinytest. - Run Meteor with tests
meteor test-packages. - Pop open your browser
http://localhost:3000. - Verify tests are passing.

Note: if your app is already running on http://localhost:3000, you can run tests separately by running meteor --port 3001 test-packages.
Contributing
Contributing, forking, and dorking is fully encouraged with Controller! If you'd like to help out with the package, take a look at the contribution guide and start hacking :)
Contributors
A special thanks to people who have contributed to Controller.
License
The code for this package is licensed under the MIT License.