An API for organizing your template logic.
- Simplified syntax for defining template logic.
- Basic Usage
- API
- Tests
- Contributing
- Contributors
- License
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"
😢 Buh. Here. Better? Thought that'd do the trick.
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.
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, 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 :)
A special thanks to people who have contributed to Controller.
The code for this package is licensed under the MIT License.