This project provides model validation, editing and rendering helpers. To utilize these helpers defines models that extend the Document model and describe their schema using JSON-Schema.
Getting Started
When defining new models that extend the Document model and add a schema attribute. For example;
The schema element must be a valid JSON schema. The quick start version of "Using JSON schema in Bones Document" is this;
Each attributes key should correspond to a property defined in the model's schema.
The type attribute should be populated, and describes the type (e.g. 'string', 'object').
The format attribute describes how display should work. this element is not required and by default everything is passed through the model's escape method. 'markdown' and 'raw' formats are also provided by Bones Document.
Tests
To complete tests successfully, you must install backbone-stash in bones-document's node_modules/ directory. Then run with
npm test
Validation
Models which extend Document will have a validate method which can be used (before saving a document to a database, for example) to validate a model's attributes.
Editing
TODO
Rendering
Models which extend Document will have a renderer method which returns an object intended to be used from within a template. This Renderer has a render method which takes the name of an attribute as an argument and returns the formatted version of that attribute.
A view for displaying a Bones Document may look like:
Of course the default formatters aren't going to be enough. It's possible to provide new ones, and select which formatter is used within a view. To define additional formatters you'll need to add them to the model's prototype. So in /models/post.bones you may have:
Alternatively, you may pass a set of attribute to formatter mappings in as options when you instantiate a renderer. For, example to specify the blinky formatter from within a view you could do;