dougal
v0.1.2
Published
The M of MVC, for Javascript VC frameworks that lack a decent M
Downloads
1
Readme
Dougal
The M of MVC, for Javascript VC frameworks that lack a decent M.
Getting Started
Install Dougal:
$ npm install aol/dougal
<script src="node_modules/dougal/dougal.js"></script>
Define models:
var Employee = Dougal.Model.extends(function () {
this.baseUrl = '/employees';
this.attribute('id');
this.attribute('name');
this.validates('name', {presence: true, message: 'Name is required'});
});
Create a new record:
var newHire = new Employee({name: 'John Doe'});
Validate the record:
newHire.isValid(); // true
newHire.name = '';
newHire.isValid(); // false
newHire.errors.name; // ['Name is required'];
Save the record:
newHire.save();
// POST /employees {name: 'John Doe'}
Angular.js integration
<script src="node_modules/dougal/dougal-angular.js"></script>
angular.module('your.app', ['dougal'])
.factory('Employee', ['Dougal', function (Dougal) {
function Employee() {
// Model definition here
}
return Dougal.Model.extends(Employee);
}])
.controller('YourController', function (Employee) {
this.employee = new Employee();
});