Permalink
Browse files

Update the documentation

  • Loading branch information...
1 parent cfa1a5e commit e428d78c9289b7c5f00b8a8b5b9d985bc5b6b5f0 @Baggz committed Mar 15, 2012
View
@@ -1,16 +1,33 @@
<a name="documentation"></a>
# Documentation
+### Engines
+
+* [JSON Schema](#jsonSchema)
+
+<a name="jsonSchema"></a>
+## JSON Schema
+
+diff.md
+
+### Example
+
+```
+// Initialize a JSON Schema validator
+var jsonSchemaValidator = amanda('json');
+```
+
<a name="methods"></a>
-## Methods
+### Methods
-* [validate](#validate)
-* [addValidator](#addValidator)
+* [validate](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#validate)
+* [addAttribute](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#addAttribute)
+* [addAttributeConstructor](https://github.com/Baggz/Amanda/tree/master/docs/json/methods/validate.md#addAttributeConstructor)
<a name="objects"></a>
-## Objects
+### Objects
-* [Schema]((https://github.com/Baggz/Amanda/tree/master/docs/objects/schema.md#schema)
+* [Schema](https://github.com/Baggz/Amanda/tree/master/docs/objects/schema.md#schema)
* [required](https://github.com/Baggz/Amanda/tree/master/docs/objects/schema.md#required)
* [minLength](https://github.com/Baggz/Amanda/tree/master/docs/objects/schema.md#minLength)
* [maxLength](https://github.com/Baggz/Amanda/tree/master/docs/objects/schema.md#maxLength)
@@ -0,0 +1,65 @@
+[← Documentation](https://github.com/Baggz/Amanda/tree/master/docs/README.md)
+
+<a name="addAttribute"></a>
+# addAttribute
+
+```javascript
+addAttribute(attributeName, attributeFn)
+```
+
+This method allows you to add a custom attribute.
+
+**Example**
+
+```javascript
+/**
+ * EvenAttribute
+ *
+ * @param {string} property
+ * @param {any} propertyValue
+ * @param {any} attributeValue
+ * @param {object} propertyAttributes
+ * @param {function} callback
+ */
+var evenAttribute = function(property, propertyValue, attributeValue, propertyAttributes, callback) {
+
+ // If ‘even: true’
+ if (attributeValue) {
+ if (typeof propertyValue === 'number' && (propertyValue % 2) !== 0) {
+ this.addError();
+ }
+ }
+
+ // Continue...
+ return callback();
+
+};
+
+// Add a new validator
+var jsonSchemaValidator = amanda('json');
+jsonSchemaValidator.addAttribute('even', evenAttribute);
+
+/**
+ * Schema
+ */
+var schema = {
+ type: 'object',
+ properties: {
+ items: {
+ type: 'number',
+ even: true // <= That's your attribute
+ }
+ }
+};
+```
+
+## Attribute API
+
+* `this.addError`
+* `this.attributes`
+* `this.instance`
+* `this.schema`
+* `this.joinPath`
+* ...
+
+> In progress...
@@ -50,8 +50,11 @@ var data = {
}
};
+
+var jsonSchemaValidator = amanda('json');
+
// Stop the validation process after a first error
-amanda.validate(data, schema, function(error) {
+jsonSchemaValidator.validate(data, schema, function(error) {
if (error) {
// Do something...
} else {
@@ -60,7 +63,7 @@ amanda.validate(data, schema, function(error) {
});
// Validate the whole schema
-amanda.validate(data, schema, { singleError: false }, function(error) {
+jsonSchemaValidator.validate(data, schema, { singleError: false }, function(error) {
if (error) {
// Do something...
} else {
@@ -3,28 +3,26 @@
<a name="error"></a>
# Error
-### Methods
-
-* [getProperties](#getProperties)
-* [getMessages](#getMessages)
-
**Example**
```javascript
[
{
property: 'users[0].username'
propertyValue: 123
- validator: 'type'
- validatorValue: 'string',
- message: 'Only string is allowed'
+ attributeName: 'type'
+ attributeValue: 'string',
+ message: 'Lorem ipsum dolor isamet pide quidu delime.'
},
- {
- // ...
- }
+ ...
]
```
+### Methods
+
+* [getProperties](#getProperties)
+* [getMessages](#getMessages)
+
<a name="getProperties"></a>
## getProperties [#](#getProperties)
@@ -11,7 +11,7 @@
<a name="singleError"></a>
## singleError [#](#singleError)
-If you set `singleError` to `false`, validation continue after first error occurred. By default `singleError` is set to `true`.
+If you set the `singleError` flag to `false`, validation continues even after a first error occurred. By default the `singleError` flag is set to `true`.
**Example**
@@ -32,7 +32,7 @@ This property allows you to set custom error messages. If you want to use more a
* `{{property}}`
* `{{propertyValue}}`
-* `{{validator}}`
+* `{{attributeValue}}`
**Example**
@@ -41,21 +41,18 @@ This property allows you to set custom error messages. If you want to use more a
* Options
*/
var options = {
+
messages: {
- // Custom error message as a string (with placeholders)
- format: 'Uh oh! Param ‘{{property}}’ must be an {{propertyValue}}.' // Uh oh! Param ‘email’ must be an email.
+ // A custom error message as a string (with placeholders)
+ format: 'Uh oh! The property ‘{{property}}’ must be an {{attributeValue}}. Well, ‘{{propertyValue}}’ doesn't look like an email. ' // Uh oh! Param ‘email’ must be an email.
- // Custom error message as a function
- enum: function(property, propertyValue, validator) {
- return 'Value of the ‘' + property + '’ property must be ' + validator.join(' or ') + '.'; // Value of the ‘sex’ property must be male or female.
+ // A custom error message as a function
+ enum: function(property, propertyValue, attributeValue) {
+ return 'Value of the ‘' + property + '’ property must be ' + attributeValue.join(' or ') + '.'; // A value of the ‘sex’ property must be male or female.
}
}
-};
-// Validate the data agains the schema and use custom error messages
-amanda.validate(data, schema, options, function(error) {
- // Do something...
-});
+};
```
Oops, something went wrong.

0 comments on commit e428d78

Please sign in to comment.