Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
/ dougal Public archive

The M of MVC, for Javascript VC frameworks that lack a decent M.

Notifications You must be signed in to change notification settings

aolarchive/dougal

Repository files navigation

Dougal

Build Status Coverage Status npm Bower

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.urlRoot = '/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();
  });