Permalink
Browse files

Rejigged the folder structure

  • Loading branch information...
1 parent 0dda798 commit 58560574f50e0b387d5e534f7742ac7d02b4acfa @anthonyshort committed Oct 10, 2012
Showing with 8 additions and 263 deletions.
  1. +2 −1 .gitignore
  2. +2 −2 README.md
  3. +1 −1 component.json
  4. +2 −2 grunt.js
  5. +0 −51 lib/errors.js
  6. +0 −63 lib/ok.js
  7. +0 −142 lib/validator.js
  8. 0 {dist → }/ok.js
  9. 0 {dist → }/ok.min.js
  10. +1 −1 test/index.html
View
@@ -1,2 +1,3 @@
node_modules/*
-components/*
+components/*
+lib/*
View
@@ -20,8 +20,8 @@ I wasn't happy with the validation libraries available for Backbone models. Most
Download the [production version][min] or the [development version][max].
-[min]: https://raw.github.com/anthonyshort/ok/master/dist/ok.min.js
-[max]: https://raw.github.com/anthonyshort/ok/master/dist/ok.js
+[min]: https://raw.github.com/anthonyshort/ok/master/ok.min.js
+[max]: https://raw.github.com/anthonyshort/ok/master/ok.js
## Usage
View
@@ -1,7 +1,7 @@
{
"name": "ok",
"version": "0.1.2",
- "main": "./dist/ok.js",
+ "main": "./ok.js",
"dependencies": {
"underscore": ">=1.4"
}
View
@@ -18,13 +18,13 @@ module.exports = function(grunt) {
'lib/validator.js',
'lib/errors.js'
],
- dest: 'dist/ok.js'
+ dest: 'ok.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
- dest: 'dist/ok.min.js'
+ dest: 'ok.min.js'
}
},
test: {
View
@@ -1,51 +0,0 @@
-(function() {
-
- OK.Errors = (function() {
-
- function Errors() {
- this.errors = {};
- this.length = 0;
- }
-
- Errors.prototype.add = function(attr, rule) {
- var _base;
- (_base = this.errors)[attr] || (_base[attr] = []);
- if (!_.contains(this.errors[attr], rule)) {
- this.length += 1;
- this.errors[attr].push(rule);
- }
- return this.errors;
- };
-
- Errors.prototype.isValid = function(attr) {
- return !(this.errors[attr] != null);
- };
-
- Errors.prototype.get = function(attr) {
- return this.errors[attr] || false;
- };
-
- Errors.prototype.invalid = function(attr) {
- if (!this.errors[attr]) {
- return false;
- }
- return this.errors[attr];
- };
-
- Errors.prototype.each = function(attr, callback) {
- if (_.isFunction(attr)) {
- return _.each(this.errors, attr, this);
- } else {
- return _.each(this.errors[attr], callback, this);
- }
- };
-
- Errors.prototype.toJSON = function() {
- return this.errors;
- };
-
- return Errors;
-
- })();
-
-}).call(this);
View
@@ -1,63 +0,0 @@
-(function() {
- var OK,
- __hasProp = {}.hasOwnProperty;
-
- OK = (function() {
-
- OK.validate = function(attributes, schema) {
- var validator;
- validator = new this(schema);
- return validator.validate(attributes);
- };
-
- function OK(schema) {
- this.schema = schema;
- }
-
- OK.prototype.validate = function(attributes) {
- var attribute, errors, ruleValue, rules, type, valid, validator, value, _ref;
- errors = new OK.Errors;
- _ref = this.schema;
- for (attribute in _ref) {
- if (!__hasProp.call(_ref, attribute)) continue;
- rules = _ref[attribute];
- value = attributes[attribute];
- if (value != null) {
- for (type in rules) {
- ruleValue = rules[type];
- if (typeof ruleValue === 'function') {
- valid = ruleValue.call(this, value, attributes);
- if (!valid) {
- errors.add(attribute, type);
- }
- } else {
- validator = new OK.Validator;
- valid = validator.check(type, value, ruleValue, attributes);
- if (!valid) {
- errors.add(attribute, type);
- }
- }
- }
- } else {
- if (rules.required === true) {
- errors.add(attribute, 'required');
- }
- }
- }
- if (typeof Object.freeze === "function") {
- Object.freeze(errors);
- }
- return errors;
- };
-
- return OK;
-
- })();
-
- if (typeof exports !== "undefined" && exports !== null) {
- exports.OK = OK;
- } else {
- this.OK = OK;
- }
-
-}).call(this);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
File renamed without changes.
File renamed without changes.
View
@@ -9,7 +9,7 @@
<script src="components/chai/chai.js"></script>
<script src="components/backbone/backbone.js"></script>
<script src="mocha-helper.js"></script>
- <script src="../dist/ok.js"></script>
+ <script src="../ok.js"></script>
<script>
mocha.setup('bdd');
window.expect = chai.expect;

0 comments on commit 5856057

Please sign in to comment.