https://github.com/colevoss/modelo
Easy to use models for web apps
https://github.com/colevoss/modelo
Last synced: about 1 year ago
JSON representation
Easy to use models for web apps
- Host: GitHub
- URL: https://github.com/colevoss/modelo
- Owner: colevoss
- License: mit
- Created: 2014-10-27T20:15:29.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-28T02:26:19.000Z (over 11 years ago)
- Last Synced: 2025-02-14T04:18:09.452Z (over 1 year ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Modelo
Easy to use js models for web apps
## About
A JavaScript library by Cole Voss.
## Installation
Using Bower:
bower install modelo
Or grab the [source](https://github.com/colevoss/modelo/dist/modelo.js) ([minified](https://github.com/colevoss/modelo/dist/modelo.min.js)).
## Usage
Basic usage is as follows:
```javascript
var Person = Modelo.extend({
constructor: function(data) {
this.base(data); // required to call parent class constructor
},
route: '/people/:id/:name/:occupation',
template: '
HEY THERE',
beforeGet: function(data) {
console.log(data); // This happens before a property is gotten
},
beforeSet: function(data) {
console.log(data); // This happens before a property is set
},
afterSet: function(data) {
console.log(data); // This happens after a property is set
},
// These validate the value of each property to the the following conditions
validations: {
name: {
type: 'string',
match: /^C/,
fail: function(err) {
console.log(err);
}
},
occupation: {
type: 'string',
fail: function(err) {
console.log(err);
}
}
}
});
cole = new Person({id: 1, name: 'Cole', occupation: 'Code Ninja'});
```
For advanced usage, see the documentation.
## Documentation
Start with `docs/MAIN.md`.
## Contributing
We'll check out your contribution if you:
* Provide a comprehensive suite of tests for your fork.
* Have a clear and documented rationale for your changes.
* Package these up in a pull request.
We'll do our best to help you out with any contribution issues you may have.
## License
MIT. See `LICENSE.txt` in this directory.