diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 94ff925..e0c1f68 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,30 +1,30 @@ - - module.exports = ( grunt ) -> srcs = [ - 'src/tails.coffee' - 'src/utils/hash.coffee' - 'src/mixins/interceptable.coffee' - 'src/mixins/debug.coffee' - 'src/mixable.coffee' - - 'src/mixins/dynamic_attributes.coffee' - 'src/collection.coffee' - 'src/mixins/collectable.coffee' - 'src/associations/relation.coffee' - 'src/associations/belongs_to_relation.coffee' - 'src/associations/has_one_relation.coffee' - 'src/associations/has_many_relation.coffee' - 'src/associations/association.coffee' - 'src/mixins/associable.coffee' - 'src/mixins/storage.coffee' - 'src/mixins/history.coffee' - - 'src/model.coffee' - 'src/template.coffee' - 'src/view.coffee' - - 'src/export.coffee' + 'tails' + 'utils/hash' + 'utils/rivets-tails' + + 'mixable' + 'mixins/interceptable' + 'mixins/debug' + 'mixins/dynamic_attributes' + + 'collection' + 'mixins/collectable' + 'associations/relation' + 'associations/belongs_to_relation' + 'associations/has_one_relation' + 'associations/has_many_relation' + 'associations/association' + 'mixins/associable' + 'mixins/storage' + 'mixins/history' + + 'model' + 'template' + 'view' + + 'config' ] deps = [ @@ -37,142 +37,140 @@ module.exports = ( grunt ) -> 'bower_components/rivets/dist/rivets.js' ] - bundle = deps.concat('build/tails.js') + # Coverage thresholds + thresholds = + lines: 60 + statements: 50 + branches: 40 + functions: 50 + + # This functions makes the config shorter and clearer later on. + # It just returns the type specific coverage config + coverage = ( type, optionsRef ) -> + optionsRef.template = require('grunt-template-jasmine-istanbul') + optionsRef.templateOptions = + coverage: 'stat/coverage/coverage.json' + thresholds: thresholds + report: + type: type + options: + dir: "stat/coverage/#{type}" - grunt.loadNpmTasks 'grunt-contrib-coffee' - grunt.loadNpmTasks 'grunt-contrib-concat' - grunt.loadNpmTasks 'grunt-contrib-uglify' - grunt.loadNpmTasks 'grunt-contrib-clean' - grunt.loadNpmTasks 'grunt-contrib-jasmine' - grunt.loadNpmTasks 'grunt-contrib-watch' - grunt.loadNpmTasks 'grunt-requirejs' - grunt.loadNpmTasks 'grunt-plato' + return optionsRef + # Configure all the tasks! grunt.initConfig pkg: grunt.file.readJSON('package.json') - meta: - banner: - '// Tails\n' + - '// version: <%= pkg.version %>\n' + - '// contributors: <%= pkg.contributors %>\n' + - '// license: <%= pkg.licenses[0].type %>\n' - coffee: - - dist: + src: options: - join: true - files: - 'dist/tails.js': srcs - - build: - options: - join: true sourceMap: true - files: - 'build/tails.js': srcs + files: [ + expand: true + cwd: 'src' + src: srcs.map ( src ) -> src + '.coffee' + dest: 'dist' + ext: '.js' + ] - modules: + spec: options: - join: false sourceMap: true files: [ expand: true - cwd: 'src' + cwd: 'spec' src: ['**/*.coffee'] - dest: '.grunt/tails/src_compiled' + dest: 'build/spec' ext: '.js' ] - spec: + perf: files: [ expand: true - cwd: 'spec' + cwd: 'perf' src: ['**/*.coffee'] - dest: '.grunt/tails/spec_compiled' + dest: 'build/perf' ext: '.js' ] + browserify: + default: + files: 'dist/tails.browser.js': 'dist/tails.js' + options: + sourceMap: false + browserifyOptions: + standalone: 'Tails' + istanbul: + files: 'build/spec/tails.browser.js': 'dist/tails.js' + options: + sourceMap: true + transform: [require('browserify-istanbul')] + browserifyOptions: + standalone: 'Tails' concat: bundle: - options: - banner: '<%= meta.banner %>' files: - 'dist/tails.bundle.js': bundle + 'dist/tails.bundle.js': deps.concat('dist/tails.browser.js') uglify: - dist: - options: - banner: '<%= meta.banner %>' - report: 'gzip' - files: - 'dist/tails.min.js': 'dist/tails.js' + default: + files: 'dist/tails.browser.min.js': 'dist/tails.browser.js' bundle: - options: - banner: '<%= meta.banner %>' - report: 'gzip' - files: - 'dist/tails.bundle.min.js': 'dist/tails.bundle.js' + files: 'dist/tails.bundle.min.js': 'dist/tails.bundle.js' jasmine: - build: - src: ['build/tails.js'] + default: + src: ['dist/tails.browser.js'] options: - specs: '.grunt/tails/spec_compiled/**/*.js' - vendor: bundle.concat('bower_components/jasmine-ajax/lib/mock-ajax.js') - template: require('grunt-template-jasmine-istanbul') - templateOptions: - coverage: 'statistics/coverage/coverage.json' - report: - type: 'lcovonly' - options: - dir: '.grunt/tails/coverage/lcov' - thresholds: - lines: 60 - statements: 60 - branches: 60 - functions: 60 + keepRunner: true + vendor: deps.concat('bower_components/jasmine-ajax/lib/mock-ajax.js') + specs: 'build/spec/**/*.js' + lcovonly: + src: ['build/spec/tails.browser.js'] + options: (coverage 'lcovonly', + keepRunner: true + vendor: deps.concat('bower_components/jasmine-ajax/lib/mock-ajax.js') + specs: 'build/spec/**/*.js' + ) html: - src: ['build/tails.js'] - options: - specs: '.grunt/tails/spec_compiled/**/*.js' - vendor: deps - template: require('grunt-template-jasmine-istanbul') - templateOptions: - coverage: 'statistics/coverage/coverage.json' - report: - type: 'html' - options: - dir: 'statistics/coverage/html' - thresholds: - lines: 60 - statements: 60 - branches: 60 - functions: 60 - - plato: - all: - options: - jshint: false - files: - 'statistics/complexity' : ['.grunt/tails/src_compiled/**/*.js'] + src: ['build/spec/tails.browser.js'] + options: (coverage 'html', + vendor: deps.concat('bower_components/jasmine-ajax/lib/mock-ajax.js') + specs: 'build/spec/**/*.js' + ) + benchmark: + default: + src: ['build/perf/**/*.js'] + dest: 'stat/perf/result.csv' clean: build: ['build'] - spec: ['.grunt/tails/spec_compiled'] - grunt: ['.grunt'] watch: - all: - files: 'src/**/*.coffee' - tasks: ['build', 'spec'] - - grunt.registerTask 'watch', ['coffee:build', 'watch'] - grunt.registerTask 'spec', ['clean:spec', 'coffee:build', 'coffee:spec', 'jasmine:build', 'clean:spec'] - grunt.registerTask 'build', ['coffee:build'] - grunt.registerTask 'dist', ['coffee:dist', 'uglify:dist'] - grunt.registerTask 'bundle', ['coffee:dist', 'concat:bundle', 'uglify:bundle'] - grunt.registerTask 'analyze', ['coffee','jasmine:html', 'plato'] + default: + files: ['src/**/*.coffee', 'spec/**/*.coffee'] + tasks: ['spec'] + + codo: + files: ['src/**/*.coffee'] + + # grunt.loadNpmTasks 'grunt-babel' + grunt.loadNpmTasks 'grunt-browserify' + grunt.loadNpmTasks 'grunt-contrib-coffee' + grunt.loadNpmTasks 'grunt-contrib-uglify' + grunt.loadNpmTasks 'grunt-contrib-watch' + grunt.loadNpmTasks 'grunt-contrib-clean' + grunt.loadNpmTasks 'grunt-contrib-jasmine' + grunt.loadNpmTasks 'grunt-benchmark' + grunt.loadNpmTasks 'grunt-codo' + grunt.loadNpmTasks 'grunt-contrib-concat' + + grunt.registerTask 'default', ['watch'] + grunt.registerTask 'dist', ['coffee:src', 'browserify:default', 'concat:bundle', 'uglify'] + grunt.registerTask 'spec', ['clean', 'dist', 'coffee:spec' ,'jasmine:default'] + grunt.registerTask 'perf', ['clean', 'dist', 'coffee:perf' ,'benchmark:default'] + grunt.registerTask 'test', ['spec', 'browserify:istanbul', 'jasmine:lcovonly'] + grunt.registerTask 'coverage', ['spec', 'browserify:istanbul', 'jasmine:html'] diff --git a/dist/associations/association.js b/dist/associations/association.js new file mode 100644 index 0000000..e351c97 --- /dev/null +++ b/dist/associations/association.js @@ -0,0 +1,103 @@ +(function() { + var Association, Collectable, Debug, DynamicAttributes, Mixable, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Mixable = require('../mixable'); + + Collectable = require('../mixins/collectable'); + + Debug = require('../mixins/debug'); + + DynamicAttributes = require('../mixins/dynamic_attributes'); + + Association = (function(_super) { + __extends(Association, _super); + + function Association() { + return Association.__super__.constructor.apply(this, arguments); + } + + _.extend(Association, Mixable); + + Association.concern(Debug); + + Association.concern(DynamicAttributes); + + Association.concern(Collectable); + + Association.prototype.relations = function() { + var Collection, Relation; + Collection = require('../collection'); + Relation = require('./relation'); + if (this._relations == null) { + this._relations = new Collection([], { + model: Relation + }); + } + return this._relations; + }; + + Association.prototype.apply = function(owner) { + var BelongsToRelation, HasManyRelation, HasOneRelation, attrs, model, models, relation; + BelongsToRelation = require('./belongs_to_relation'); + HasOneRelation = require('./has_one_relation'); + HasManyRelation = require('./has_many_relation'); + attrs = { + association: this, + from: this.get('from'), + to: this.get('to'), + name: this.get('name'), + owner: owner + }; + switch (this.get('type')) { + case 'belongsTo': + model = owner.get(attrs.name); + relation = new BelongsToRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.to.name || attrs.to.toString().match(/^function\s*([^\s(]+)/)[1]) + })); + if (model != null) { + relation.set("target", model); + } + break; + case 'hasOne': + model = owner.get(attrs.name); + relation = new HasOneRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), + through: this.get('through'), + source: this.get('source') || this.get('name') + })); + if (model != null) { + relation.set("target", model); + } + break; + case 'hasMany': + models = owner.get(attrs.name); + relation = new HasManyRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), + through: this.get('through'), + source: this.get('source') || this.get('name') + })); + if (models != null) { + relation.set("target", models); + } + } + this.relations().add(relation); + owner.relations().add(relation); + owner.getter(attrs.name, function() { + return relation.get('target'); + }); + return owner.setter(attrs.name, function(value) { + return relation.set('target', value); + }); + }; + + return Association; + + })(Backbone.Model); + + module.exports = Association; + +}).call(this); + +//# sourceMappingURL=association.js.map diff --git a/dist/associations/association.js.map b/dist/associations/association.js.map new file mode 100644 index 0000000..4b0c108 --- /dev/null +++ b/dist/associations/association.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "association.js", + "sourceRoot": "../../src/associations/", + "sources": [ + "association.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,2DAAA;IAAA;mSAAA;;AAAA,EAAA,OAAA,GAAU,OAAA,CAAQ,YAAR,CAAV,CA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CAAC,IAAnB,EAAyB,SAAC,KAAD,GAAA;eAAU,QAAQ,CAAC,GAAT,CAAa,QAAb,EAAuB,KAAvB,EAAV;MAAA,CAAzB,EAtCK;IAAA,CAbP,CAAA;;uBAAA;;KADwB,QAAQ,CAAC,MALnC,CAAA;;AAAA,EA2DA,MAAM,CAAC,OAAP,GAAiB,WA3DjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/associations/belongs_to_relation.js b/dist/associations/belongs_to_relation.js new file mode 100644 index 0000000..df18c93 --- /dev/null +++ b/dist/associations/belongs_to_relation.js @@ -0,0 +1,51 @@ +(function() { + var BelongsToRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + BelongsToRelation = (function(_super) { + __extends(BelongsToRelation, _super); + + function BelongsToRelation() { + return BelongsToRelation.__super__.constructor.apply(this, arguments); + } + + BelongsToRelation.prototype.initialize = function() { + var association, foreignKey, owner, to; + association = this.get('association'); + to = association.get('to'); + foreignKey = this.get('foreignKey'); + owner = this.get('owner'); + this.getter({ + target: function() { + return to.get(owner.get(foreignKey)); + } + }); + this.setter({ + target: function(model) { + if (model == null) { + this.set(foreignKey, null); + return; + } + if (to.all().get(model.id) == null) { + to.all().add(model, { + parse: true + }); + } + return owner.set(foreignKey, model.id); + } + }); + return BelongsToRelation.__super__.initialize.apply(this, arguments); + }; + + return BelongsToRelation; + + })(Relation); + + module.exports = BelongsToRelation; + +}).call(this); + +//# sourceMappingURL=belongs_to_relation.js.map diff --git a/dist/associations/belongs_to_relation.js.map b/dist/associations/belongs_to_relation.js.map new file mode 100644 index 0000000..09ab81e --- /dev/null +++ b/dist/associations/belongs_to_relation.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "belongs_to_relation.js", + "sourceRoot": "../../src/associ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,OAAP,GAAiB,iBAxBjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/associations/has_many_relation.js b/dist/associations/has_many_relation.js new file mode 100644 index 0000000..f44664f --- /dev/null +++ b/dist/associations/has_many_relation.js @@ -0,0 +1,112 @@ +(function() { + var Collection, HasManyRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + Collection = require('../collection'); + + HasManyRelation = (function(_super) { + __extends(HasManyRelation, _super); + + function HasManyRelation() { + return HasManyRelation.__super__.constructor.apply(this, arguments); + } + + HasManyRelation.prototype.initialize = function() { + var association, collection, foreignKey, name, owner, source, sourceAssociation, through, throughAssociation, to; + association = this.get('association'); + to = association.get('to'); + owner = this.get('owner'); + name = this.get('name'); + foreignKey = this.get('foreignKey'); + through = this.get('through'); + source = this.get('source'); + if (through == null) { + collection = to.all().where(foreignKey).is(owner.id); + collection.parent = owner; + this.getter({ + target: (function(_this) { + return function() { + return collection; + }; + })(this) + }); + return this.setter({ + target: (function(_this) { + return function(models) { + collection.each(function(model) { + return model.unset(foreignKey); + }); + return collection.add(models); + }; + })(this) + }); + } else { + throughAssociation = owner.constructor.associations().findWhere({ + name: through + }); + if (throughAssociation.get('type') !== 'hasMany') { + return this.getter({ + target: (function(_this) { + return function() { + return owner.get(through).get(source || name); + }; + })(this) + }); + } else { + sourceAssociation = (source && throughAssociation.get('to').associations().findWhere({ + name: source + })) || throughAssociation.get('to').associations().findWhere({ + name: name, + type: 'hasMany' + }) || throughAssociation.get('to').associations().findWhere({ + name: inflection.singularize(name) + }); + if (sourceAssociation.get('type') === 'hasMany') { + source = sourceAssociation.get('name'); + return this.lazy({ + target: function() { + var union; + union = new Collection.Union(); + union.parent = owner; + owner.get(through).each((function(_this) { + return function(model) { + return union.addCollection(model.get(source)); + }; + })(this)); + owner.get(through).on('add', (function(_this) { + return function(model) { + return union.addCollection(model.get(source)); + }; + })(this)); + owner.get(through).on('remove', (function(_this) { + return function(model) { + return union.removeCollection(model.get(source)); + }; + })(this)); + return union; + } + }); + } else { + source = sourceAssociation.get('name'); + return this.lazy({ + target: function() { + return owner.get(through).pluck(source); + } + }); + } + } + } + }; + + return HasManyRelation; + + })(Relation); + + module.exports = HasManyRelation; + +}).call(this); + +//# sourceMappingURL=has_many_relation.js.map diff --git a/dist/associations/has_many_relation.js.map b/dist/associations/has_many_relation.js.map new file mode 100644 index 0000000..9d68c1b --- /dev/null +++ b/dist/associations/has_many_relation.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "has_many_relation.js", + "sourceRoot": "../../src/associations/", + "sources": [ + "has_many_relation.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,qCAAA;IAAA;mSAAA;;AAAA,EAAA,QAAA,GAAW,OAAA,CAAQ,YAAR,CAAX,CAAA;;AAAA,EACA,UAAA,GAAa,OAAA,CAAQ,eAAR,CADb,CAAA;;AAAA,EAGM;AAEJ,sCAAA,CAAA;;;;KAAA;;AAAA,8BAAA,UAAA,GAAY,SAAA,GAAA;AACV,UAAA,4GAAA;AAAA,MAAA,WAAA,GAAc,IAAC,CAAA,GAAD,CAAK,aAAL,CAAd,CAAA;AAAA,MACA,EAAA,GAAc,WAAW,CAAC,GAAZ,CAAgB,IAAhB,CADd,CAAA;AAAA,MAEA,KAAA,GAAc,IAAC,CAAA,GAAD,CAAK,OAAL,CAFd,CAAA;AAAA,MAIA,IAAA,GAAc,IAAC,CAAA,GAAD,CAAK,MAAL,CAJd,CAAA;AAAA,MAKA,UAAA,GAAc,IAAC,CAAA,GAAD,CAAK,YAAL,CALd,CAAA;AAAA,MAMA,OAAA,GAAc,IAAC,CAAA,GAAD,CAAK,SAAL,CANd,CAAA;AAAA,MAOA,MAAA,GAAc,IAAC,CAAA,GAAD,CAAK,QAAL,CAPd,CA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BAAA,SAAE,KAAF,GAAA;2BAAa,KAAK,CAAC,aAAN,CAAoB,KAAK,CAAC,GAAN,CAAU,MAAV,CAApB,EAAb;kBAAA,EAAA;gBAAA,CAAA,CAAA,CAAA,IAAA,CAAhC,CAHA,CAAA;AAAA,gBAIA,KAAK,CAAC,GAAN,CAAU,OAAV,CAAkB,CAAC,EAAnB,CAAsB,QAAtB,EAAgC,CAAA,SAAA,KAAA,GAAA;yBAAA,SAAE,KAAF,GAAA;2BAAa,KAAK,CAAC,gBAAN,CAAuB,KAAK,CAAC,GAAN,CAAU,MAAV,CAAvB,EAAb;kBAAA,EAAA;gBAAA,CAAA,CAAA,CAAA,IAAA,CAAhC,CAJA,CAAA;AAKA,uBAAO,KAAP,CANY;cAAA,CAAR;aAAN,EAFF;WAAA,MAAA;AAUE,YAAA,MAAA,GAAS,iBAAiB,CAAC,GAAlB,CAAsB,MAAtB,CAAT,CAAA;mBACA,IAAC,CAAA,IAAD,CAAM;AAAA,cAAA,MAAA,EAAQ,SAAA,GAAA;uBAAG,KAAK,CAAC,GAAN,CAAU,OAAV,CAAkB,CAAC,KAAnB,CAAyB,MAAzB,EAAH;cAAA,CAAR;aAAN,EAXF;WAPF;SAnBF;OAVU;IAAA,CAAZ,CAAA;;2BAAA;;KAF4B,SAH9B,CAAA;;AAAA,EAsDA,MAAM,CAAC,OAAP,GAAiB,eAtDjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/associations/has_one_relation.js b/dist/associations/has_one_relation.js new file mode 100644 index 0000000..35d7390 --- /dev/null +++ b/dist/associations/has_one_relation.js @@ -0,0 +1,69 @@ +(function() { + var HasOneRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + HasOneRelation = (function(_super) { + __extends(HasOneRelation, _super); + + function HasOneRelation() { + return HasOneRelation.__super__.constructor.apply(this, arguments); + } + + HasOneRelation.prototype.initialize = function() { + var association, foreignKey, owner, source, through, to; + owner = this.get('owner'); + association = this.get('association'); + to = association.get('to'); + foreignKey = this.get('foreignKey'); + through = this.get('through'); + source = this.get('source'); + if (through == null) { + this.getter({ + target: (function(_this) { + return function() { + return to.all().where(foreignKey).is(owner.id).first(); + }; + })(this) + }); + this.setter({ + target: (function(_this) { + return function(model) { + var _ref; + if ((_ref = to.all().where(foreignKey).is(owner.id).first()) != null) { + _ref.unset(foreignKey); + } + return model.set(foreignKey, owner.id); + }; + })(this) + }); + } else { + this.getter({ + target: (function(_this) { + return function() { + return owner.get(through).get(source); + }; + })(this) + }); + this.setter({ + target: (function(_this) { + return function(model) { + return owner.get(through).set(source, model); + }; + })(this) + }); + } + return HasOneRelation.__super__.initialize.apply(this, arguments); + }; + + return HasOneRelation; + + })(Relation); + + module.exports = HasOneRelation; + +}).call(this); + +//# sourceMappingURL=has_one_relation.js.map diff --git a/dist/associations/has_one_relation.js.map b/dist/associations/has_one_relation.js.map new file mode 100644 index 0000000..19876e4 --- /dev/null +++ b/dist/associations/has_one_relation.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "has_one_relation.js", + "sourceRoot": "../../src/associations/", + "sources": [ + "has_one_relation.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,wBAAA;IAAA;mSAAA;;AAAA,EAAA,QAAA,GAAW,OAAA,CAAQ,YAAR,CAAX,CAAA;;AAAA,EAEM;AAEJ,qCAAA,CAAA;;;;KAAA;;AAAA,6BAAA,UAAA,GAAY,SAAA,GAAA;AACV,UAAA,mDAAA;AAAA,MAAA,KAAA,GAAc,IAAC,CAAA,GAAD,CAAK,OAAL,CAAd,CAAA;AAAA,MACA,WAAA,GAAc,IAAC,CAAA,GAAD,CAAK,aAAL,CADd,CAAA;AAAA,MAEA,EAAA,GAAc,WAAW,CAAC,GAAZ,CAAgB,IAAhB,CAF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AAC,GAAN,CAAU,OAAV,CAAkB,CAAC,GAAnB,CAAuB,MAAvB,EAA+B,KAA/B,EAAb;YAAA,EAAA;UAAA,CAAA,CAAA,CAAA,IAAA,CAAR;SAAR,CADA,CAPF;OARA;aAkBA,gDAAA,SAAA,EAnBU;IAAA,CAAZ,CAAA;;0BAAA;;KAF2B,SAF7B,CAAA;;AAAA,EAyBA,MAAM,CAAC,OAAP,GAAiB,cAzBjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/associations/relation.js b/dist/associations/relation.js new file mode 100644 index 0000000..6cb0b83 --- /dev/null +++ b/dist/associations/relation.js @@ -0,0 +1,35 @@ +(function() { + var Collectable, DynamicAttributes, Mixable, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Mixable = require('../mixable'); + + DynamicAttributes = require('../mixins/dynamic_attributes'); + + Collectable = require('../mixins/collectable'); + + Relation = (function(_super) { + __extends(Relation, _super); + + function Relation() { + return Relation.__super__.constructor.apply(this, arguments); + } + + _.extend(Relation, Mixable); + + Relation.concern(DynamicAttributes); + + Relation.concern(Collectable); + + Relation.prototype.initialize = function() {}; + + return Relation; + + })(Backbone.Model); + + module.exports = Relation; + +}).call(this); + +//# sourceMappingURL=relation.js.map diff --git a/dist/associations/relation.js.map b/dist/associations/relation.js.map new file mode 100644 index 0000000..3f6956b --- /dev/null +++ b/dist/associations/relation.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "relation.js", + "sourceRoot": "../../src/associations/", + "sources": [ + "relation.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,iDAAA;IAAA;mSAAA;;AAAA,EAAA,OAAA,GAAoB,OAAA,CAAQ,YAAR,CAApB,CAAA;;AAAA,EACA,iBAAA,GAAoB,OAAA,CAAQ,8BAAR,CADpB,CAAA;;AAAA,EAEA,WAAA,GAAoB,OAAA,CAAQ,uBAAR,CAFpB,CAAA;;AAAA,EAIM;AACJ,+BAAA,CAAA;;;;KAAA;;AAAA,IAAA,CAAC,CAAC,MAAF,CAAS,QAAT,EAAY,OAAZ,CAAA,CAAA;;AAAA,IACA,QAAC,CAAA,OAAD,CAAS,iBAAT,CADA,CAAA;;AAAA,IAEA,QAAC,CAAA,OAAD,CAAS,WAAT,CAFA,CAAA;;AAAA,uBAIA,UAAA,GAAY,SAAA,GAAA,CAJZ,CAAA;;oBAAA;;KADqB,QAAQ,CAAC,MAJhC,CAAA;;AAAA,EAmBA,MAAM,CAAC,OAAP,GAAiB,QAnBjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/collection.js b/dist/collection.js new file mode 100644 index 0000000..8e8050c --- /dev/null +++ b/dist/collection.js @@ -0,0 +1,507 @@ +(function() { + var Collection, Mixable, Model, config, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Mixable = require('./mixable'); + + Model = require('./model'); + + config = require('./config'); + + Collection = (function(_super) { + __extends(Collection, _super); + + _.extend(Collection, Mixable); + + Collection.prototype.syncedAt = 0; + + function Collection(models, options) { + if (models == null) { + models = []; + } + if (options == null) { + options = {}; + } + this.model = options.model || this.model || Model; + this.parent = options.parent || this.parent; + this.synced = options.synced || false; + this.on('change', (function(_this) { + return function(model) { + return _this.synced = false; + }; + })(this)); + this.on('sync', (function(_this) { + return function() { + _this.synced = true; + return _this.syncedAt = Date.now(); + }; + })(this)); + Collection.__super__.constructor.apply(this, arguments); + } + + Collection.prototype.urlRoot = function() { + return inflection.transform(this.model.name || this.model.toString().match(/^function\s*([^\s(]+)/)[1], ['underscore', 'pluralize']); + }; + + Collection.prototype.url = function() { + var base, format, root, url, _ref, _ref1; + base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || config.url; + root = (typeof this.urlRoot === "function" ? this.urlRoot() : void 0) || this.urlRoot; + format = this.format != null ? '.' + ((typeof this.format === "function" ? this.format() : void 0) || this.format) : ''; + url = "" + base + "/" + root + format; + return url; + }; + + Collection.prototype.fetch = function(options) { + var deferred, fetchPromise, reject, resolve; + if (options == null) { + options = {}; + } + if (!options.force) { + if (this.syncing) { + return this._fetchPromise; + } else if (this.synced) { + deferred = Q.defer(); + deferred.resolve(); + return deferred.promise; + } + } + options.dataType || (options.dataType = this.format); + fetchPromise = Collection.__super__.fetch.call(this, options); + this.synced = false; + this.syncing = true; + deferred = Q.defer(); + resolve = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.resolve.apply(deferred, args); + }; + })(this); + reject = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.reject.apply(deferred, args); + }; + })(this); + fetchPromise.then((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (_this.synced) { + return resolve.apply(null, args); + } else { + return _this.once('sync', function() { + return resolve.apply(null, args); + }); + } + }; + })(this)); + fetchPromise.fail((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return reject.apply(null, args); + }; + })(this)); + return this._fetchPromise = deferred.promise; + }; + + Collection.prototype.filter = function(filter) { + return new Collection.Filtered(this, { + filter: filter + }); + }; + + Collection.prototype.where = function(attrs, first) { + var assimilate, distantiate, filter, key, query; + if (first != null) { + return Collection.__super__.where.call(this, attrs, first); + } + if (typeof attrs === 'object') { + filter = function(model) { + var key, value; + for (key in attrs) { + value = attrs[key]; + if (model.get(key) !== value) { + return false; + } + } + return true; + }; + assimilate = function(model) { + var key, value, _results; + _results = []; + for (key in attrs) { + value = attrs[key]; + _results.push(model.set(key, value)); + } + return _results; + }; + distantiate = function(model) { + var key, value, _results; + _results = []; + for (key in attrs) { + value = attrs[key]; + _results.push(model.unset(key)); + } + return _results; + }; + return new Collection.Filtered(this, { + filter: filter, + assimilate: assimilate, + distantiate: distantiate + }); + } else if (typeof attrs === 'string') { + key = attrs; + query = { + is: (function(_this) { + return function(value) { + var selector, _base, _base1, _base2; + (selector = {})[key] = value; + return (_base = ((_base1 = ((_base2 = (_this._where || (_this._where = {})))[key] || (_base2[key] = {}))).is || (_base1.is = {})))[value] || (_base[value] = _this.where(selector)); + }; + })(this), + "in": (function(_this) { + return function(values) { + return _this.filter(function(model) { + var _ref; + return _ref = model.get(key), __indexOf.call(values, _ref) >= 0; + }); + }; + })(this), + atLeast: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) >= value; + }); + }; + })(this), + atMost: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) <= value; + }); + }; + })(this), + greaterThan: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) > value; + }); + }; + })(this), + lessThan: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) < value; + }); + }; + })(this) + }; + return query; + } + }; + + Collection.prototype.pluck = function(attribute) { + return new Collection.Plucked(this, { + attribute: attribute + }); + }; + + Collection.prototype.parse = function(response, options) { + var attrs, model, models, _i, _len; + if (!(response instanceof Array)) { + response = [response]; + } + models = []; + for (_i = 0, _len = response.length; _i < _len; _i++) { + attrs = response[_i]; + if (attrs instanceof Backbone.Model) { + models.push(attrs); + break; + } + model = this.model.get(attrs.id); + model.set(attrs); + models.push(model); + } + return models; + }; + + return Collection; + + })(Backbone.Deferred.Collection); + + Collection.Plucked = (function(_super) { + __extends(Plucked, _super); + + function Plucked(collection, options) { + if (options == null) { + options = {}; + } + this.collection = collection; + this.attribute = options.attribute; + this.length = 0; + Plucked.__super__.constructor.call(this, [], options); + this.collection.each((function(_this) { + return function(model) { + return _this.trigger('add', model.get(_this.attribute)); + }; + })(this)); + this.listenTo(collection, "change:" + this.attribute, (function(_this) { + return function(model) { + var previousValue, value; + value = model.get(_this.attribute); + previousValue = model.previous(_this.attribute); + if (previousValue != null) { + _this.trigger('remove', previousValue); + } + if (value != null) { + return _this.trigger('add', value); + } + }; + })(this)); + this.listenTo(collection, 'add', (function(_this) { + return function(model) { + var value; + value = model.get(_this.attribute); + if (value != null) { + _this.trigger('add', value); + } + return _this.length++; + }; + })(this)); + this.listenTo(collection, 'remove', (function(_this) { + return function(model) { + var value; + value = model.get(_this.attribute); + if (value != null) { + _this.trigger('remove', value); + } + return _this.length--; + }; + })(this)); + } + + Plucked.prototype.contains = function(value) { + return __indexOf.call(this.toArray(), value) >= 0; + }; + + Plucked.prototype.include = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.contains.apply(this, args); + }; + + Plucked.prototype.each = function(fn) { + return this.collection.each((function(_this) { + return function(model) { + return fn(model.get(_this.attribute)); + }; + })(this)); + }; + + Plucked.prototype.forEach = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.each.apply(this, args); + }; + + Plucked.prototype.toArray = function() { + var model; + return (function() { + var _i, _len, _ref, _results; + _ref = this.collection.toArray(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + model = _ref[_i]; + _results.push(model.get(this.attribute)); + } + return _results; + }).call(this); + }; + + return Plucked; + + })(Collection); + + Collection.Filtered = (function(_super) { + __extends(Filtered, _super); + + function Filtered(collection, options) { + if (options == null) { + options = {}; + } + this.collection = collection; + this.model = this.collection.model; + this.filter = options.filter; + this.assimilate = options.assimilate; + this.distantiate = options.distantiate; + Filtered.__super__.constructor.call(this, [], options); + this.collection.each((function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } + }; + })(this)); + this.listenTo(this.collection, 'add', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } + }; + })(this)); + this.listenTo(this.collection, 'remove', (function(_this) { + return function(model) { + return _this.remove(model); + }; + })(this)); + this.listenTo(this.collection, 'change', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } else { + return _this.remove(model); + } + }; + })(this)); + this.on('add', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return; + } + if (_this.assimilate == null) { + _this.remove(model); + throw Error("Cannot assimilate model."); + } + _this.assimilate(model); + return _this.collection.add(model); + }; + })(this)); + this.on('remove', (function(_this) { + return function(model) { + if (!_this.collection.contains(model)) { + return; + } + if (!_this.filter(model)) { + return; + } + if (_this.distantiate == null) { + _this.add(model); + throw Error("Cannot distantiate model."); + } + return _this.distantiate(model); + }; + })(this)); + } + + return Filtered; + + })(Collection); + + Collection.Multi = (function(_super) { + __extends(Multi, _super); + + function Multi(collections, options) { + var collection, _i, _len; + if (collections == null) { + collections = []; + } + if (options == null) { + options = {}; + } + this.collections = []; + this.modelCounts = {}; + Multi.__super__.constructor.call(this, [], options); + for (_i = 0, _len = collections.length; _i < _len; _i++) { + collection = collections[_i]; + this.addCollection(collection); + } + } + + Multi.prototype.increment = function(model) { + var _base, _name; + (_base = this.modelCounts)[_name = model.cid] || (_base[_name] = 0); + return ++this.modelCounts[model.cid]; + }; + + Multi.prototype.decrement = function(model) { + var _base, _name; + (_base = this.modelCounts)[_name = model.cid] || (_base[_name] = 0); + return --this.modelCounts[model.cid]; + }; + + Multi.prototype.addCollection = function(collection) { + if (!(collection instanceof Backbone.Collection)) { + return; + } + this.model || (this.model = collection.model); + this.collections.push(collection); + collection.each((function(_this) { + return function(model) { + return _this.increment(model); + }; + })(this)); + this.listenTo(collection, 'add', this.increment); + this.listenTo(collection, 'remove', this.decrement); + return this.trigger('addCollection', collection); + }; + + Multi.prototype.removeCollection = function(collection) { + var index; + if (!(collection instanceof Backbone.Collection)) { + return; + } + index = this.collections.indexOf(collection); + if (!(index >= 0)) { + return; + } + this.collections = this.collections.slice(0, index).concat(this.collections.slice(index + 1, this.collections.length)); + collection.each((function(_this) { + return function(model) { + return _this.decrement(model); + }; + })(this)); + this.stopListening(collection); + return this.trigger('removeCollection', collection); + }; + + return Multi; + + })(Collection); + + Collection.Union = (function(_super) { + __extends(Union, _super); + + function Union() { + return Union.__super__.constructor.apply(this, arguments); + } + + Union.prototype.increment = function(model) { + if (Union.__super__.increment.apply(this, arguments) === 1) { + return this.add(model); + } + }; + + Union.prototype.decrement = function(model) { + if (Union.__super__.decrement.apply(this, arguments) === 0) { + return this.remove(model); + } + }; + + return Union; + + })(Collection.Multi); + + module.exports = Collection; + +}).call(this); + +//# sourceMappingURL=collection.js.map diff --git a/dist/collection.js.map b/dist/collection.js.map new file mode 100644 index 0000000..1f5714d --- /dev/null +++ b/dist/collection.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "collection.js", + "sourceRoot": "../src/", + "sources": [ + "collection.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,kCAAA;IAAA;;;yJAAA;;AAAA,EAAA,OAAA,GAAU,OAAA,CAAQ,WAAR,CAAV,CAAA;;AAAA,EACA,KAAA,GAAQ,OAAA,CAAQ,SAAR,CADR,CAAA;;AAAA,EAEA,MAAA,GAAS,OAAA,CAAQ,UAAR,CAFT,CAAA;;AAAA,EAIM;AACJ,iCAAA,CAAA;;AAAA,IAAA,CAAC,CAAC,MAAF,CAAS,UAAT,EAAY,OAAZ,CAAA,CAAA;;AAAA,yBAGA,QAAA,GAAU,CAHV,CAAA;;AAKa,IAAA,oBAAE,MAAF,EAAe,OAAf,GAAA;;QAAE,SAAS;OACtB;;QAD0B,UAAU;OACpC;AAAA,MAAA,IAAC,CAAA,KAAD,GAAU,OAAO,CAAC,KAAR,IAAkB,IAAC,CAAA,KAAnB,IAA4B,KAAtC,CAAA;AAAA,MACA,IAAC,CAAA,MAAD,GAAU,OAAO,CAAC,MAAR,IAAkB,IAAC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,CAA4B,CAAC,MAA7B,CAAoC,IAAC,CAAA,WAAW,CAAC,KAAb,CAAmB,KAAA,GAAQ,CAA3B,EAA8B,IAAC,CAAA,WAAW,CAAC,MAA3C,CAApC,CAJf,CAAA;AAAA,MAMA,UAAU,CAAC,IAAX,CAAgB,CAAA,SAAA,KAAA,GAAA;eAAA,SAAE,KAAF,GAAA;iBACd,KAAC,CAAA,SAAD,CAAW,KAAX,EADc;QAAA,EAAA;MAAA,CAAA,CAAA,CAAA,IAAA,CAAhB,CANA,CAAA;AAAA,MASA,IAAC,CAAA,aAAD,CAAe,UAAf,CATA,CAAA;aAUA,IAAC,CAAA,OAAD,CAAS,kBAAT,EAA6B,UAA7B,EAXgB;IAAA,CA7BlB,CAAA;;iBAAA;;KAF6B,WAnO/B,CAAA;;AAAA,EAiRM,UAAU,CAAC;AAEf,4BAAA,CAAA;;;;KAAA;;AAAA,oBAAA,SAAA,GAAW,SAAE,KAAF,GAAA;AACT,MAAA,IAAc,sCAAA,SAAA,CAAA,KAAS,CAAvB;eAAA,IAAC,CAAA,GAAD,CAAK,KAAL,EAAA;OADS;IAAA,CAAX,CAAA;;AAAA,oBAGA,SAAA,GAAW,SAAE,KAAF,GAAA;AACT,MAAA,IAAiB,sCAAA,SAAA,CAAA,KAAS,CAA1B;eAAA,IAAC,CAAA,MAAD,CAAQ,KAAR,EAAA;OADS;IAAA,CAHX,CAAA;;iBAAA;;KAF6B,UAAU,CAAC,MAjR1C,CAAA;;AAAA,EAyRA,MAAM,CAAC,OAAP,GAAiB,UAzRjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/config.js b/dist/config.js new file mode 100644 index 0000000..1d76d0f --- /dev/null +++ b/dist/config.js @@ -0,0 +1,8 @@ +(function() { + module.exports = { + url: 'http://localhost' + }; + +}).call(this); + +//# sourceMappingURL=config.js.map diff --git a/dist/config.js.map b/dist/config.js.map new file mode 100644 index 0000000..494a412 --- /dev/null +++ b/dist/config.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "config.js", + "sourceRoot": "../src/", + "sources": [ + "config.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,EAAA,MAAM,CAAC,OAAP,GACE;AAAA,IAAA,GAAA,EAAK,kBAAL;GADF,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixable.js b/dist/mixable.js new file mode 100644 index 0000000..7668878 --- /dev/null +++ b/dist/mixable.js @@ -0,0 +1,144 @@ +(function() { + var Mixable, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, + __slice = [].slice; + + Mixable = { + MixableKeywords: ['included', 'extended', 'constructor', 'Interactions', 'InstanceMethods', 'ClassMethods'], + _include: function(mixin) { + var funcs, key, value, _ref; + if (mixin.InstanceMethods != null) { + funcs = mixin.InstanceMethods; + } else if (mixin.ClassMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this.prototype[key] = value; + } + } + } + return (_ref = funcs.included) != null ? _ref.apply(this) : void 0; + }, + _extend: function(mixin) { + var funcs, key, value, _ref; + if (mixin.ClassMethods != null) { + funcs = mixin.ClassMethods; + } else if (mixin.InstanceMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this[key] = value; + } + } + } + return (_ref = funcs.extended) != null ? _ref.apply(this) : void 0; + }, + include: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._includedMixins) != null ? _ref.klass : void 0) !== this) { + this._includedMixins = _(this._includedMixins).clone() || []; + this._includedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._includedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._includedMixins.push(mixin); + } + this._include(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + _ref1 = this._includedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + return this; + }, + extend: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._extendedMixins) != null ? _ref.klass : void 0) !== this) { + this._extendedMixins = _(this._extendedMixins).clone() || []; + this._extendedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._extendedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._extendedMixins.push(mixin); + } + this._extend(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + _ref1 = this._extendedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + return this; + }, + "with": function(mixin, funcs) { + if (funcs == null) { + funcs = {}; + } + if ((this._includedMixins != null) && __indexOf.call(this._includedMixins, mixin) >= 0) { + return funcs; + } else if ((this._extendedMixins != null) && __indexOf.call(this._extendedMixins, mixin) >= 0) { + return funcs; + } else { + return null; + } + }, + concern: function() { + var mixin, mixins, _i, _len; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + this.include(mixin); + this.extend(mixin); + } + return this; + } + }; + + module.exports = Mixable; + +}).call(this); + +//# sourceMappingURL=mixable.js.map diff --git a/dist/mixable.js.map b/dist/mixable.js.map new file mode 100644 index 0000000..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,EAAS,SAAA,GAAA;AACP,UAAA,uBAAA;AAAA,MADS,gEACT,CAAA;AAAA,WAAA,6CAAA;2BAAA;AACE,QAAA,IAAC,CAAA,OAAD,CAAS,KAAT,CAAA,CAAA;AAAA,QACA,IAAC,CAAA,MAAD,CAAQ,KAAR,CADA,CADF;AAAA,OAAA;AAGA,aAAO,IAAP,CAJO;IAAA,CA1GT;GAFF,CAAA;;AAAA,EAkHA,MAAM,CAAC,OAAP,GAAiB,OAlHjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/associable.js b/dist/mixins/associable.js new file mode 100644 index 0000000..f30bd0a --- /dev/null +++ b/dist/mixins/associable.js @@ -0,0 +1,89 @@ +(function() { + var Associable, Association, Relation; + + Relation = require('../associations/relation'); + + Association = require('../associations/association'); + + Associable = { + InstanceMethods: { + relations: function() { + var Collection; + Collection = require('../collection'); + if (this._relations == null) { + this._relations = new Collection([], { + model: Relation + }); + } + return this._relations; + } + }, + ClassMethods: { + belongsTo: function(options) { + return this.associate('belongsTo', options); + }, + hasOne: function(options) { + return this.associate('hasOne', options); + }, + hasMany: function(options) { + return this.associate('hasMany', options); + }, + associate: function(type, options) { + var association, attrs, name, to; + name = _(options).keys()[0]; + to = options[name]; + attrs = { + type: type, + from: this, + name: name, + foreignKey: options.foreignKey, + through: options.through, + source: options.source + }; + association = new Association(attrs); + if (to.prototype instanceof Backbone.Model) { + return association.set({ + to: to + }); + } else { + return association.getter({ + to: to + }); + } + }, + associations: function() { + var _ref; + if (!((_ref = this._associations) != null ? _ref.klass = this : void 0)) { + this._associations = Association.all().where({ + from: this + }); + this._associations.klass = this; + } + return this._associations; + }, + extended: function() { + var Collectable, DynamicAttributes, Interceptable; + DynamicAttributes = require('./dynamic_attributes'); + Collectable = require('./collectable'); + Interceptable = require('./interceptable'); + this.concern(DynamicAttributes); + this.concern(Collectable); + this.concern(Interceptable); + return this.before({ + initialize: function() { + return this.constructor.associations().each((function(_this) { + return function(association) { + return association.apply(_this); + }; + })(this)); + } + }); + } + } + }; + + module.exports = Associable; + +}).call(this); + +//# sourceMappingURL=associable.js.map diff --git a/dist/mixins/associable.js.map b/dist/mixins/associable.js.map new file mode 100644 index 0000000..4916494 --- /dev/null +++ b/dist/mixins/associable.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "associable.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "associable.coffee" + ], + "names": [], + "mappings": "AAOA;AAAA,MAAA,iCAAA;;AAAA,EAAA,QAAA,GAAa,OAAA,CAAQ,0BAAR,CAAb,CAAA;;AAAA,EACA,WAAA,GAAc,OAAA,CAAQ,6BAAR,CADd,CAAA;;AAAA,EAGA,UAAA,GAEE;AAAA,IAAA,eAAA,EACE;AAAA,MAAA,SAAA,EAAW,SAAA,GAAA;AACT,YAAA,UAAA;AAAA,QAAA,UAAA,GAAa,OAAA,CAAQ,eAAR,CAAb,CAAA;AAEA,QAAA,IAAO,uBAAP;AACE,UAAA,IAAC,CAAA,UAAD,GAAkB,IAAA,UAAA,CAAW,EAAX,EAAe;AAAA,YAAA,KAAA,EAAO,QAAP;WAAf,CAAlB,CADF;SAFA;AAIA,eAAO,IAAC,CAAA,UAAR,CALS;MAAA,CAAX;KADF;AAAA,IAQA,YAAA,EACE;AAAA,MAAA,SAAA,EAAW,SAAE,OAAF,GAAA;eACT,IAAC,CAAA,SAAD,CAAW,WAAX,EAAwB,OAAxB,EADS;MAAA,CAAX;AAAA,MAGA,MAAA,EAAQ,SAAE,OAAF,GAAA;eACN,IAAC,CAAA,SAAD,CAAW,QAAX,EAAqB,OAArB,EADM;MAAA,CAHR;AAAA,MAMA,OAAA,EAAS,SAAE,OAAF,GAAA;eACP,IAAC,CAAA,SAAD,CAAW,SAAX,EAAsB,OAAtB,EADO;MAAA,CANT;AAAA,MASA,SAAA,EAAW,SAAE,IAAF,EAAQ,OAAR,GAAA;AACT,YAAA,4BAAA;AAAA,QAAA,IAAA,GAAS,CAAA,CAAE,OAAF,CAAU,CAAC,IAA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iBAAR,CAFhB,CAAA;AAAA,QAIA,IAAC,CAAA,OAAD,CAAS,iBAAT,CAJA,CAAA;AAAA,QAKA,IAAC,CAAA,OAAD,CAAS,WAAT,CALA,CAAA;AAAA,QAMA,IAAC,CAAA,OAAD,CAAS,aAAT,CANA,CAAA;eAQA,IAAC,CAAA,MAAD,CAAQ;AAAA,UAAA,UAAA,EAAY,SAAA,GAAA;mBAClB,IAAC,CAAA,WAAW,CAAC,YAAb,CAAA,CAA2B,CAAC,IAA5B,CAAiC,CAAA,SAAA,KAAA,GAAA;qBAAA,SAAE,WAAF,GAAA;uBAAmB,WAAW,CAAC,KAAZ,CAAkB,KAAlB,EAAnB;cAAA,EAAA;YAAA,CAAA,CAAA,CAAA,IAAA,CAAjC,EADkB;UAAA,CAAZ;SAAR,EATQ;MAAA,CAhCV;KATF;GALF,CAAA;;AAAA,EA0DA,MAAM,CAAC,OAAP,GAAiB,UA1DjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/collectable.js b/dist/mixins/collectable.js new file mode 100644 index 0000000..c113930 --- /dev/null +++ b/dist/mixins/collectable.js @@ -0,0 +1,64 @@ +(function() { + var Collectable, Interceptable; + + Interceptable = require('./interceptable'); + + Collectable = { + InstanceMethods: { + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + if ((this.id != null) && (this.constructor.all().get(this.id) != null)) { + throw new Error("Duplicate " + this.constructor.name + " for id " + this.id + "."); + } + return this.constructor.all().add(this); + } + }); + } + }, + ClassMethods: { + all: function() { + var Collection, _ref; + Collection = require('../collection'); + if (((_ref = this._all) != null ? _ref.klass : void 0) !== this) { + this._all = new Collection(null, { + model: this + }); + this._all.klass = this; + } + return this._all; + }, + get: function(id) { + return this.all().get(id) || new this({ + id: id + }); + }, + scope: function(name, options) { + return this[name] = this.all().where(options.where); + } + }, + Interactions: function() { + var Storage; + Storage = require('./storage'); + return { + ClassMethods: this["with"](Storage, { + extended: function() { + return this.all().on('add remove', (function(_this) { + return function(instance) { + if (instance.id != null) { + return _this.store(); + } + }; + })(this)); + } + }) + }; + } + }; + + module.exports = Collectable; + +}).call(this); + +//# sourceMappingURL=collectable.js.map diff --git a/dist/mixins/collectable.js.map b/dist/mixins/collectable.js.map new file mode 100644 index 0000000..1fff4b7 --- /dev/null +++ b/dist/mixins/collectable.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "collectable.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "collectable.coffee" + ], + "names": [], + "mappings": "AAKA;AAAA,MAAA,0BAAA;;AAAA,EAAA,aAAA,GAAgB,OAAA,CAAQ,iBAAR,CAAhB,CAAA;;AAAA,EAEA,WAAA,GAEE;AAAA,IAAA,eAAA,EACE;AAAA,MAAA,QAAA,EAAU,SAAA,GAAA;AACR,QAAA,IAAC,CAAA,OAAD,CAAS,aAAT,CAAA,CAAA;eAEA,IAAC,CAAA,KAAD,CAAO;AAAA,UAAA,UAAA,EAAY,SAAA,GAAA;AACjB,YAAA,IAAG,iBAAA,IAAS,6CAAZ;AACE,oBAAU,IAAA,KAAA,CAAO,YAAA,GAAW,IAAC,CAAA,WAAW,CAAC,IAAxB,GAA8B,UAA9B,GAAuC,IAAC,CAAA,EAAxC,GAA4C,GAAnD,CAAV,CADF;aAAA;mBAEA,IAAC,CAAA,WAAW,CAAC,GAAb,CAAA,CAAkB,CAAC,GAAnB,CAAuB,IAAvB,EAHiB;UAAA,CAAZ;SAAP,EAHQ;MAAA,CAAV;KADF;AAAA,IASA,YAAA,EACE;AAAA,MAAA,GAAA,EAAK,SAAA,GAAA;AACH,YAAA,gBAAA;AAAA,QAAA,UAAA,GAAgB,OAAA,CAAQ,eAAR,CAAhB,CAAA;AACA,QAAA,sCAAY,CAAE,eAAP,KAAgB,IAAvB;AACE,UAAA,IAAC,CAAA,IAAD,GAAY,IAAA,UAAA,CAAW,IAAX,EAAiB;AAAA,YAAA,KAAA,EAAO,IAAP;WAAjB,CAAZ,CAAA;AAAA,UACA,IAAC,CAAA,IAAI,CAAC,KAAN,GAAc,IADd,CADF;SADA;AAIA,eAAO,IAAC,CAAA,IAAR,CALG;MAAA,CAAL;AAAA,MAOA,GAAA,EAAK,SAAE,EAAF,GAAA;eACH,IAAC,CAAA,GAAD,CAAA,CAAM,CAAC,GAAP,CAAW,EAAX,CAAA,IAAsB,IAAA,IAAA,CAAE;AAAA,UAAA,EAAA,EAAI,EAAJ;SAAF,EADnB;MAAA,CAPL;AAAA,MAUA,KAAA,EAAO,SAAE,IAAF,EAAQ,OAAR,GAAA;eACL,IAAE,CAAA,IAAA,CAAF,GAAU,IAAC,CAAA,GAAD,CAAA,CAAM,CAAC,KAAP,CAAa,OAAO,CAAC,KAArB,EADL;MAAA,CAVP;KAVF;AAAA,IAuBA,YAAA,EAAc,SAAA,GAAA;AACZ,UAAA,OAAA;AAAA,MAAA,OAAA,GAAgB,OAAA,CAAQ,WAAR,CAAhB,CAAA;aACA;AAAA,QAAA,YAAA,EACE,IAAC,CAAA,MAAA,CAAD,CAAM,OAAN,EACE;AAAA,UAAA,QAAA,EAAU,SAAA,GAAA;mBACR,IAAC,CAAA,GAAD,CAAA,CAAM,CAAC,EAAP,CAAU,YAAV,EAAwB,CAAA,SAAA,KAAA,GAAA;qBAAA,SAAE,QAAF,GAAA;AACtB,gBAAA,IAAY,mBAAZ;yBAAA,KAAC,CAAA,KAAD,CAAA,EAAA;iBADsB;cAAA,EAAA;YAAA,CAAA,CAAA,CAAA,IAAA,CAAxB,EADQ;UAAA,CAAV;SADF,CADF;QAFY;IAAA,CAvBd;GAJF,CAAA;;AAAA,EAmCA,MAAM,CAAC,OAAP,GAAiB,WAnCjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/debug.js b/dist/mixins/debug.js new file mode 100644 index 0000000..07c8689 --- /dev/null +++ b/dist/mixins/debug.js @@ -0,0 +1,119 @@ +(function() { + var Debug, Interceptable, + __slice = [].slice, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Interceptable = require('./interceptable'); + + Debug = { + InstanceMethods: { + LOG_LEVELS: { + "ERROR": true, + "WARNING": true, + "INFO": false + }, + _excludedMethods: _.union(Object.keys(Interceptable.InstanceMethods), ["constructor", "log", "message", "warn", "error", "info"]), + debug: function() { + return this.LOG_LEVELS.INFO = true; + }, + message: function() { + var line, thing, things, _i, _len; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = "" + (new Date()) + " - "; + for (_i = 0, _len = things.length; _i < _len; _i++) { + thing = things[_i]; + if (thing.constructor.name === "String") { + line += thing + " "; + } else { + line += JSON.stringify(thing) + " "; + } + } + line += "in " + this.constructor.name + "(" + this.id + ")"; + return line; + }, + error: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.ERROR) { + return; + } + line = this.message.apply(this, things); + return console.error(line); + }, + warn: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.WARNING) { + return; + } + line = this.message.apply(this, things); + return console.warn(line); + }, + log: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = this.message.apply(this, things); + return console.log(line); + }, + info: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.INFO) { + return; + } + line = this.message.apply(this, things); + return console.log(line); + }, + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + var args, funcs, key, value, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + this.info("Called function 'initialize' of " + this.constructor.name + " with arguments:", args); + this.on("change", (function(_this) { + return function(event) { + return _this.info("Change of attributes:", event.changedAttributes()); + }; + })(this)); + funcs = (function() { + var _results; + _results = []; + for (key in this) { + value = this[key]; + if (value instanceof Function && __indexOf.call(this._excludedMethods, key) < 0) { + _results.push(key); + } else { + continue; + } + } + return _results; + }).call(this); + _results = []; + for (_i = 0, _len = funcs.length; _i < _len; _i++) { + key = funcs[_i]; + _results.push((function(_this) { + return function(key) { + return _this.after({ + "these": [key], + "do": function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.info("Called function '" + key + "' of " + this.constructor.name + " with arguments:", args); + } + }); + }; + })(this)(key)); + } + return _results; + } + }); + } + } + }; + + module.exports = Debug; + +}).call(this); + +//# sourceMappingURL=debug.js.map diff --git a/dist/mixins/debug.js.map b/dist/mixins/debug.js.map new file mode 100644 index 0000000..6edc01c --- /dev/null +++ b/dist/mixins/debug.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "debug.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "debug.coffee" + ], + "names": [], + "mappings": "AAIA;AAAA,MAAA,oBAAA;IAAA;yJAAA;;AAAA,EAAA,aAAA,GAAgB,OAAA,CAAQ,iBAAR,CAAhB,CAAA;;AAAA,EAEA,KAAA,GAEE;AAAA,IAAA,eAAA,EACE;AAAA,MAAA,UAAA,EACE;AAAA,QAAA,OAAA,EAAY,IAAZ;AAAA,QACA,SAAA,EAAY,IADZ;AAAA,QAEA,MAAA,EAAY,KAFZ;OADF;AAAA,MAKA,gBAAA,EAAmB,CAAC,CAAC,KAAF,CAAQ,MAAM,CAAC,IAAP,CAAY,aAAa,CAAC,eAA1B,CAAR,EAAoD,CACrE,aADqE,EACtD,KADsD,EAC/C,SAD+C,EACpC,MADoC,EAC5B,OAD4B,EACnB,MADmB,CAApD,CALnB;AAAA,MASA,KAAA,EAAO,SAAA,GAAA;eACL,IAAC,CAAA,UAAU,CAAC,IAAZ,GAAmB,KADd;MAAA,CATP;AAAA,MAYA,OAAA,EAAS,SAAA,GAAA;AACP,YAAA,6BAAA;AAAA,QADQ,gEACR,CAAA;AAAA,QAAA,IAAA,GAAO,EAAA,GAAE,CAAI,IAAA,IAAA,CAAA,CAAJ,CAAF,GAAc,KAArB,CAAA;AACA,aAAA,6CAAA;6BAAA;AACE,UAAA,IAAG,KAAK,CAAC,WA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,OAAvB,GAA6B,IAAC,CAAA,WAAW,CAAC,IAA1C,GAAgD,kBAAvD,EAA0E,IAA1E,EAD4B;oBAAA,CAAvB;mBAAP,EADC;gBAAA,EAAA;cAAA,CAAA,CAAA,CAAA,IAAA,CAAH,CAAI,GAAJ,EAAA,CADF;AAAA;4BAXiB;UAAA,CAAZ;SAAP,EAHQ;MAAA,CA3CV;KADF;GAJF,CAAA;;AAAA,EAmEA,MAAM,CAAC,OAAP,GAAiB,KAnEjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/dynamic_attributes.js b/dist/mixins/dynamic_attributes.js new file mode 100644 index 0000000..4a3fa4d --- /dev/null +++ b/dist/mixins/dynamic_attributes.js @@ -0,0 +1,157 @@ +(function() { + var DynamicAttributes, Interceptable; + + Interceptable = require('./interceptable'); + + DynamicAttributes = { + InstanceMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.defineAttribute({ + getter: getters + }); + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.defineAttribute({ + setter: setters + }); + }, + lazy: function(attributes, fn) { + var key, name, _results; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + _results = []; + for (key in attributes) { + fn = attributes[key]; + _results.push((function(_this) { + return function(key, fn) { + _this.getter(key, function() { + return _this.attributes[key] = (_this[fn] || fn).call(_this); + }); + return _this.setter(key, function(value) { + delete _this.attributes[key]; + return _this.attributes[key] = value; + }); + }; + })(this)(key, fn)); + } + return _results; + }, + defineAttribute: function(params) { + var attributes, fn, key, type, _results; + _results = []; + for (type in params) { + attributes = params[type]; + if (type === 'getter' || type === 'setter') { + _results.push((function() { + var _results1; + _results1 = []; + for (key in attributes) { + fn = attributes[key]; + _results1.push((function(_this) { + return function(key, fn) { + var map; + map = Object.getOwnPropertyDescriptor(_this.attributes, key) || { + configurable: true + }; + delete _this.attributes[key]; + delete map.value; + delete map.writable; + if (type === 'getter') { + map.get = function() { + return (_this[fn] || fn).call(_this); + }; + } else if (type === 'setter') { + map.set = function(value) { + var result; + return result = (_this[fn] || fn).call(_this, value); + }; + } + return Object.defineProperty(_this.attributes, key, map); + }; + })(this)(key, fn)); + } + return _results1; + }).call(this)); + } + } + return _results; + } + }, + ClassMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.getter(getters); + } + }); + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.setter(setters); + } + }); + }, + lazy: function(attributes, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.lazy(attributes); + } + }); + }, + extended: function() { + return this.concern(Interceptable); + } + } + }; + + module.exports = DynamicAttributes; + +}).call(this); + +//# sourceMappingURL=dynamic_attributes.js.map diff --git a/dist/mixins/dynamic_attributes.js.map b/dist/mixins/dynamic_attributes.js.map new file mode 100644 index 0000000..ebfdf85 --- /dev/null +++ b/dist/mixins/dynamic_attributes.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "dynamic_attributes.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "dynamic_attributes.coffee" + ], + "names": [], + "mappings": "AAKA;AAAA,MAAA,gCAAA;;AAAA,EAAA,aAAA,GAAgB,OAAA,CAAQ,iBAAR,CAAhB,CAAA;;AAAA,EAEA,iBAAA,GACE;AAAA,IAAA,eAAA,EACE;AAAA,MAAA,MAAA,EAAQ,SAAE,OAAF,EAAW,EAAX,GAAA;A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;AAAA,MAYA,IAAA,EAAM,SAAE,UAAF,EAAc,EAAd,GAAA;AACJ,YAAA,IAAA;;UADkB,KAAK;SACvB;AAAA,QAAA,IAAG,MAAA,CAAA,UAAA,KAAqB,QAArB,IAAkC,YAArC;AACE,UAAA,IAAA,GAAO,UAAP,CAAA;AAAA,UACA,CAAC,UAAA,GAAa,EAAd,CAAkB,CAAA,IAAA,CAAlB,GAA0B,EAD1B,CADF;SAAA;eAGA,IAAC,CAAA,MAAD,CAAQ;AAAA,UAAA,UAAA,EAAY,SAAA,GAAA;mBAAO,IAAC,CAAA,IAAD,CAAM,UAAN,EAAP;UAAA,CAAZ;SAAR,EAJI;MAAA,CAZN;AAAA,MAkBA,QAAA,EAAU,SAAA,GAAA;eACR,IAAC,CAAA,OAAD,CAAS,aAAT,EADQ;MAAA,CAlBV;KApCF;GAHF,CAAA;;AAAA,EA4DA,MAAM,CAAC,OAAP,GAAiB,iBA5DjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/history.js b/dist/mixins/history.js new file mode 100644 index 0000000..8d8b0f1 --- /dev/null +++ b/dist/mixins/history.js @@ -0,0 +1,92 @@ +(function() { + var History, Storage; + + Storage = require('./storage'); + + History = { + Interactions: function() { + return { + InstanceMethods: this["with"](Storage, { + diff: function() { + var diff, key, prevAttrs, value, _ref; + diff = {}; + diff.apply = (function(_this) { + return function(context) { + var change, key, type, values; + if (context == null) { + context = _this; + } + for (key in diff) { + change = diff[key]; + for (type in change) { + values = change[type]; + switch (type) { + case "create": + context.set(key, values["value"]); + break; + case "update": + context.set(key, values["new"]); + break; + case "delete": + context.unset(key); + } + } + } + return context; + }; + })(this); + prevAttrs = this.constructor.retrieve(this.id) || {}; + _ref = this.attributes; + for (key in _ref) { + value = _ref[key]; + if (prevAttrs[key] !== this.get(key)) { + if (prevAttrs[key] != null) { + diff[key] = { + "update": { + "old": prevAttrs[key], + "new": this.get(key) + } + }; + } else { + diff[key] = { + "create": { + "value": this.get(key) + } + }; + } + } + } + for (key in prevAttrs) { + value = prevAttrs[key]; + if (!this.has(key)) { + diff[key] = { + "delete": { + "value": value + } + }; + } + } + return diff; + }, + commit: function() { + var key; + key = this.store(this.diff()); + return key; + }, + included: function() { + return this.after({ + initialize: function() { + return this.on("change", this.commit); + } + }); + } + }) + }; + } + }; + + module.exports = History; + +}).call(this); + +//# sourceMappingURL=history.js.map diff --git a/dist/mixins/history.js.map b/dist/mixins/history.js.map new file mode 100644 index 0000000..d6b6ac6 --- /dev/null +++ b/dist/mixins/history.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "history.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "history.coffee" + ], + "names": [], + "mappings": "AAEA;AAAA,MAAA,gBAAA;;AAAA,EAAA,OAAA,GAAU,OAAA,CAAQ,WAAR,CAAV,CAAA;;AAAA,EAEA,OAAA,GAEE;AAAA,IAAA,YAAA,EAAc,SAAA,GAAA;aACZ;AAAA,QAAA,eAAA,EACE,IAAC,CAAA,MAAA,CAAD,CAAM,OAAN,EACE;AAAA,UAAA,IAAA,EAAM,SAAA,GAAA;AACJ,gBAAA,iCAAA;AAAA,YAAA,IAAA,GAAO,EAAP,CAAA;AAAA,YAEA,IAAI,CAAC,KAAL,GAAa,CAAA,SAAA,KAAA,GAAA;qBAAA,SAAC,OAAD,GAAA;AAEX,oBAAA,yBAAA;;kBAFY,UAAU;iBAEtB;AAAA,qBAAA,WAAA;qCAAA;AACE,uBAAA,cAAA;0CAAA;AACE,4BAAO,IAAP;AAAA,2BACO,QADP;AAEI,wBAAA,OAAO,CAAC,GAAR,CAAY,GAAZ,EAAiB,MAAO,CAAA,OAAA,CAAxB,CAAA,CAFJ;AACO;AADP,2BAGO,QAHP;AAII,wBAAA,OAAO,CAAC,GAAR,CAAY,GAAZ,EAAiB,MAAO,CAAA,KAAA,CAAxB,CAAA,CAJJ;AAGO;AAHP,2BAKO,QALP;AAMI,wBAAA,OAAO,CAAC,KAAR,CAAc,GAAd,CAAA,CANJ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GAAA;mBACR,IAAC,CAAA,KAAD,CAAO;AAAA,cAAA,UAAA,EAAY,SAAA,GAAA;uBACjB,IAAC,CAAA,EAAD,CAAI,QAAJ,EAAc,IAAC,CAAA,MAAf,EADiB;cAAA,CAAZ;aAAP,EADQ;UAAA,CAvCV;SADF,CADF;QADY;IAAA,CAAd;GAJF,CAAA;;AAAA,EAkDA,MAAM,CAAC,OAAP,GAAiB,OAlDjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/interceptable.js b/dist/mixins/interceptable.js new file mode 100644 index 0000000..998b427 --- /dev/null +++ b/dist/mixins/interceptable.js @@ -0,0 +1,180 @@ +(function() { + var Interceptable, + __slice = [].slice; + + Interceptable = { + InstanceMethods: { + before: function(interceptors) { + return this.intercept({ + before: interceptors + }); + }, + after: function(interceptors) { + return this.intercept({ + after: interceptors + }); + }, + intercept: function(params) { + var fn, fns, interceptors, k, key, klass, placement, v, _i, _len, _ref, _results; + klass = this.constructor; + _results = []; + for (placement in params) { + interceptors = params[placement]; + if (!(placement === 'before' || placement === 'after')) { + continue; + } + if (interceptors.these != null) { + _ref = interceptors.these; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + if (typeof key === 'function') { + for (k in this) { + v = this[k]; + if (key === v) { + key = k; + break; + } + } + } + interceptors[key] = interceptors["do"]; + } + } + interceptors = _(interceptors).omit('these', 'do'); + _results.push((function() { + var _results1; + _results1 = []; + for (key in interceptors) { + fns = interceptors[key]; + if (!_(fns).isArray()) { + fns = [fns]; + } + _results1.push((function() { + var _j, _len1, _results2; + _results2 = []; + for (_j = 0, _len1 = fns.length; _j < _len1; _j++) { + fn = fns[_j]; + _results2.push((function(_this) { + return function(key, fn) { + var after, before, interceptable, prev, _ref1, _ref2, _ref3, _ref4; + if ((_this.hasOwnProperty(key) || klass.prototype.hasOwnProperty(key)) && !((_this[key].before != null) || (_this[key].after != null))) { + interceptable = _this[key]; + return _this[key] = function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (placement === 'before') { + (this[fn] || fn).apply(this, args); + } + ret = interceptable.apply(this, args); + if (placement === 'after') { + (this[fn] || fn).apply(this, args); + } + return ret; + }; + } else { + before = ((_ref1 = _this[key]) != null ? _ref1.klass : void 0) === klass ? (_ref2 = _this[key]) != null ? _ref2.before : void 0 : void 0; + after = ((_ref3 = _this[key]) != null ? _ref3.klass : void 0) === klass ? (_ref4 = _this[key]) != null ? _ref4.after : void 0 : void 0; + if (placement === 'before') { + prev = before; + before = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (prev != null) { + prev.apply(this, args); + } + return (this[fn] || fn).apply(this, args); + }; + } else if (placement === 'after') { + prev = after; + after = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + (this[fn] || fn).apply(this, args); + return prev != null ? prev.apply(this, args) : void 0; + }; + } + return Object.defineProperty(_this, key, { + configurable: true, + set: function(interceptable) { + return Object.defineProperty(this, key, { + writable: true, + value: function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + ret = interceptable.apply(this, args); + if (after != null) { + after.apply(this, args); + } + return ret; + } + }); + }, + get: function() { + var interceptor; + interceptor = function() { + var args, ret, superFn, _ref5; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + superFn = (_ref5 = this.constructor.__super__) != null ? _ref5[key] : void 0; + if ((superFn != null ? superFn.klass : void 0) !== klass) { + ret = superFn != null ? superFn.apply(this, args) : void 0; + } + if (after != null) { + after.apply(this, args); + } + return ret; + }; + interceptor.before = before; + interceptor.after = after; + interceptor.klass = klass; + return interceptor; + } + }); + } + }; + })(this)(key, fn)); + } + return _results2; + }).call(this)); + } + return _results1; + }).call(this)); + } + return _results; + } + }, + ClassMethods: { + before: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.before(interceptors.call(this)); + } + }); + } else { + return this.prototype.before(interceptors); + } + }, + after: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.after(interceptors.call(this)); + } + }); + } else { + return this.prototype.after(interceptors); + } + } + } + }; + + module.exports = Interceptable; + +}).call(this); + +//# sourceMappingURL=interceptable.js.map diff --git a/dist/mixins/interceptable.js.map b/dist/mixins/interceptable.js.map new file mode 100644 index 0000000..f726c9c --- /dev/null +++ b/dist/mixins/interceptable.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "interceptable.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "interceptable.coffee" + ], + "names": [], + "mappings": "AAWA;AAAA,MAAA,aAAA;IAAA,kBAAA;;AAAA,EAAA,aAAA,GAEE;AAAA,IAAA,eAAA,EACE;AAAA,MAAA,MAAA,EAAQ,SAAE,YAAF,GAAA;eACN,IAAC,CAAA,SAAD,CAAW;AAAA,UAAA,MAAA,EAAQ,YAAR;SAAX,EADM;MAAA,CAAR;AAAA,MAGA,KAAA,EAAO,SAAE,YAAF,GAAA;eACL,IAAC,CAAA,SAAD,CAAW;AAAA,UAAA,KAAA,EAAO,YAAP;SAAX,EADK;MAAA,CAHP;AAAA,MAMA,SAAA,EAAW,SAAE,MAAF,GAAA;AACT,YAAA,4EAAA;AAAA,QAAA,KAAA,GAAQ,IAAC,CAAA,WAAT,CAAA;AACA;aAAA,mBAAA;2CAAA;gBAA2C,SAAA,KAAc,QAAd,IAAA,SAAA,KAAwB;;WAIjE;AAAA,UAAA,IAAG,0BAAH;AACE;AAAA,iBAAA,2CAAA;6BAAA;AAIE,cAAA,IAAgD,MAAA,CAAA,GAAA,KAAc,UAA9D;AAAA,qBAAA,SAAA;8BAAA;sBAAoC,GAAA,KAAO;AAA1C,oBAAA,GAAA,GAAM,CAAN,CAAA;AAAS;mBAAV;AAAA,iBAAA;eAAA;AAAA,cACA,YAAa,CAAA,GAAA,CAAb,GAAoB,YAAY,CAAC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IAAb,CAAkB,IAAlB,CAAR,EAAH;YAAA,CAAZ;WAAR,EADF;SAAA,MAAA;iBAEK,IAAC,CAAA,SAAE,CAAA,MAAH,CAAU,YAAV,EAFL;SADM;MAAA,CAAR;AAAA,MAKA,KAAA,EAAO,SAAE,YAAF,GAAA;AACL,QAAA,IAAG,sEAAH;iBACE,IAAC,CAAA,MAAD,CAAQ;AAAA,YAAA,UAAA,EAAY,SAAA,GAAA;qBAAG,IAAC,CAAA,KAAD,CAAO,YAAY,CAAC,IAAb,CAAkB,IAAlB,CAAP,EAAH;YAAA,CAAZ;WAAR,EADF;SAAA,MAAA;iBAEK,IAAC,CAAA,SAAE,CAAA,KAAH,CAAS,YAAT,EAFL;SADK;MAAA,CALP;KAtGF;GAFF,CAAA;;AAAA,EAkHA,MAAM,CAAC,OAAP,GAAiB,aAlHjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/mixins/storage.js b/dist/mixins/storage.js new file mode 100644 index 0000000..28848d2 --- /dev/null +++ b/dist/mixins/storage.js @@ -0,0 +1,133 @@ +(function() { + var Collectable, Debug, Hash, Interceptable, Storage; + + Interceptable = require('./interceptable'); + + Hash = require('../utils/hash'); + + Debug = require('./debug'); + + Collectable = require('./collectable'); + + Storage = { + InstanceMethods: { + storage: function() { + return this.constructor.storage(); + }, + indexRoot: function() { + return this.constructor.indexRoot(); + }, + store: function(data) { + return this.constructor.store(this, data); + }, + retrieve: function(hash) { + return _.defaults(this.attributes, this.constructor.retrieve(this.id, hash)); + }, + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + this.on("sync", this.store); + this.retrieve(); + return this.store(); + } + }); + } + }, + ClassMethods: { + storage: function() { + return localStorage; + }, + toJSON: function(obj) { + return JSON.stringify(obj); + }, + indexRoot: function() { + return inflection.transform(this.name, ['underscore', 'pluralize']); + }, + store: function(instance, data) { + var indexRoot, json, key, _ref; + if (!((instance != null) && (instance.id != null))) { + return; + } + indexRoot = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + key = "" + indexRoot + "/" + instance.id; + if (data != null) { + key += "/" + Hash(this.toJSON(data)); + json = this.toJSON({ + "instance": instance, + "data": data + }); + } else { + json = this.toJSON(instance); + } + this.storage().setItem(key, json); + return key; + }, + retrieve: function(id, hash) { + var ids, indexRoot, json, key, _i, _len, _ref; + indexRoot = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + if (id != null) { + key = "" + indexRoot + "/" + id; + if (hash != null) { + key += "/" + hash; + } + json = this.storage().getItem(key); + if (json != null) { + return JSON.parse(json); + } + } else { + json = this.storage().getItem(Hash(indexRoot)); + ids = JSON.parse(json); + if (json != null) { + for (_i = 0, _len = ids.length; _i < _len; _i++) { + id = ids[_i]; + this.retrieve(id); + } + } + return ids; + } + } + }, + Interactions: function() { + return { + InstanceMethods: this["with"](Debug, { + included: (function(_this) { + return function() { + return _this.after({ + initialize: function() { + console.log(this.toJSON(this.name)); + return this.after({ + store: function() { + return this.log("Stored instances", this.constructor.all().pluck("id")); + } + }); + } + }); + }; + })(this) + }), + ClassMethods: this["with"](Collectable, { + indexRoot: function() { + var _ref; + return (_ref = typeof this.urlRoot === "function" ? this.urlRoot() : void 0) != null ? _ref : this.urlRoot; + }, + extended: function() { + return this.after({ + store: function() { + var json, key, _ref; + key = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + json = this.toJSON(this.constructor.all().pluck("id")); + return this.constructor.storage().setItem(key, json); + } + }); + } + }) + }; + } + }; + + module.exports = Storage; + +}).call(this); + +//# sourceMappingURL=storage.js.map diff --git a/dist/mixins/storage.js.map b/dist/mixins/storage.js.map new file mode 100644 index 0000000..f82b60c --- /dev/null +++ b/dist/mixins/storage.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "storage.js", + "sourceRoot": "../../src/mixins/", + "sources": [ + "storage.coffee" + ], + "names": [], + "mappings": "AAIA;AAAA,MA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A,CAAA,CAAA,IAAA,CAAX;SADe,CAAjB;AAAA,QAOA,YAAA,EACE,IAAC,CAAA,MAAA,CAAD,CAAM,WAAN,EACE;AAAA,UAAA,SAAA,EAAW,SAAA,GAAA;AACT,gBAAA,IAAA;AAAA,0GAAqB,IAAC,CAAA,OAAtB,CADS;UAAA,CAAX;AAAA,UAEA,QAAA,EAAU,SAAA,GAAA;mBACR,IAAC,CAAA,KAAD,CAAO;AAAA,cAAA,KAAA,EAAO,SAAA,GAAA;AACZ,oBAAA,eAAA;AAAA,gBAAA,GAAA,8FAAsB,IAAC,CAAA,SAAvB,CAAA;AAAA,gBACA,IAAA,GAAO,IAAC,CAAA,MAAD,CAAQ,IAAC,CAAA,WAAW,CAAC,GAAb,CAAA,CAAkB,CAAC,KAAnB,CAAyB,IAAzB,CAAR,CADP,CAAA;uBAEA,IAAC,CAAA,WAAW,CAAC,OAAb,CAAA,CAAsB,CAAC,OAAvB,CAA+B,GAA/B,EAAoC,IAApC,EAHY;cAAA,CAAP;aAAP,EADQ;UAAA,CAFV;SADF,CARF;QADY;IAAA,CA3Dd;GARF,CAAA;;AAAA,EAqFA,MAAM,CAAC,OAAP,GAAiB,OArFjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/model.js b/dist/model.js new file mode 100644 index 0000000..6936d23 --- /dev/null +++ b/dist/model.js @@ -0,0 +1,139 @@ +(function() { + var Associable, Mixable, Model, config, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice; + + Mixable = require('./mixable'); + + Associable = require('./mixins/associable'); + + config = require('./config'); + + Model = (function(_super) { + __extends(Model, _super); + + function Model() { + return Model.__super__.constructor.apply(this, arguments); + } + + _.extend(Model, Mixable); + + Model.concern(Associable); + + Model.prototype.syncedAt = 0; + + Model.prototype.initialize = function(attrs, options) { + var _ref; + if (attrs == null) { + attrs = {}; + } + if (options == null) { + options = {}; + } + this.parent = options.parent || this.parent || ((_ref = this.collection) != null ? _ref.parent : void 0); + this.synced = options.synced || false; + this.on('change', (function(_this) { + return function(model) { + return _this.synced = false; + }; + })(this)); + this.on('sync', (function(_this) { + return function() { + _this.synced = true; + return _this.syncedAt = Date.now(); + }; + })(this)); + return Model.__super__.initialize.apply(this, arguments); + }; + + Model.prototype.urlRoot = function() { + return inflection.transform(this.constructor.name || this.constructor.toString().match(/^function\s*([^\s(]+)/)[1], ['underscore', 'pluralize']); + }; + + Model.prototype.url = function() { + var base, format, id, root, url, _ref, _ref1; + base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || config.url; + root = (typeof this.urlRoot === "function" ? this.urlRoot() : void 0) || this.urlRoot; + id = this.id ? "/" + this.id : ''; + format = this.format != null ? '.' + ((typeof this.format === "function" ? this.format() : void 0) || this.format) : ''; + url = "" + base + "/" + root + id + format; + return url; + }; + + Model.prototype.fetch = function(options) { + var deferred, fetchPromise, reject, resolve; + if (options == null) { + options = {}; + } + if (!options.force) { + if (this.syncing) { + return this._fetchPromise; + } else if (this.synced) { + deferred = Q.defer(); + deferred.resolve(); + return deferred.promise; + } + } + options.dataType || (options.dataType = this.format); + fetchPromise = Model.__super__.fetch.call(this, options); + this.synced = false; + this.syncing = true; + deferred = Q.defer(); + resolve = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.resolve.apply(deferred, args); + }; + })(this); + reject = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.reject.apply(deferred, args); + }; + })(this); + fetchPromise.then((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (_this.synced) { + return resolve.apply(null, args); + } else { + return _this.once('sync', function() { + return resolve.apply(null, args); + }); + } + }; + })(this)); + fetchPromise.fail((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return reject.apply(null, args); + }; + })(this)); + return this._fetchPromise = deferred.promise; + }; + + Model.prototype.save = function(options) { + if (options == null) { + options = {}; + } + return Model.__super__.save.call(this, _.defaults(options, { + dataType: this.format + })); + }; + + return Model; + + })(Backbone.Deferred.Model); + + module.exports = Model; + +}).call(this); + +//# sourceMappingURL=model.js.map diff --git a/dist/model.js.map b/dist/model.js.map new file mode 100644 index 0000000..575f136 --- /dev/null +++ b/dist/model.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "model.js", + "sourceRoot": "../src/", + "sources": [ + "model.coffee" + ], + "names": [], + "mappings": "AAAA;AAAA,MAAA,kCAAA;IAAA;;sBAAA;;AAAA,EAAA,OAAA,GAAc,OAAA,CAAQ,WAAR,CAAd,CAAA;;AAAA,EACA,UAAA,GAAc,OAAA,CAAQ,qBAAR,CADd,CAAA;;AAAA,EAEA,MAAA,GAAc,OAAA,CAAQ,UAAR,CAFd,CAAA;;AAAA,EAIM;AACJ,4BAAA,CAAA;;;;KAAA;;AAAA,IAAA,CAAC,CAAC,MAAF,CAAS,KAAT,EAAY,OAAZ,CAAA,CAAA;;AAAA,IACA,KAAC,CAAA,OAAD,CAAS,UAAT,CADA,CAAA;;AAAA,oBAGA,QAAA,GAAU,CAHV,CAAA;;AAAA,oBAKA,UAAA,GAAY,SAAE,KAAF,EAAc,OAAd,GAAA;AACV,UAAA,IAAA;;QADY,QAAQ;OACpB;;QADwB,UAAU;OAClC;AAAA,MAAA,IAAC,CAAA,MAAD,GAAU,OAAO,CAAC,MAAR,IAAkB,IAAC,CAAA,MAAnB,4CAAwC,CAAE,gBAApD,CAAA;AAAA,MACA,IAAC,CAAA,MAAD,GAAU,OAAO,CAAC,MAAR,IAAkB,KAD5B,CAAA;AAAA,MAGA,IAAC,CAAA,EAAD,CAAI,QAAJ,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AC,KAAhB,CAAsB,QAAtB,EAAgC,IAAhC,EAFO;QAAA,EAAA;MAAA,CAAA,CAAA,CAAA,IAAA,CAnBT,CAAA;AAAA,MAuBA,YAAY,CAAC,IAAb,CAAkB,CAAA,SAAA,KAAA,GAAA;eAAA,SAAA,GAAA;AAChB,cAAA,IAAA;AAAA,UADkB,8DAClB,CAAA;AAAA,UAAA,IAAK,KAAC,CAAA,MAAN;mBAAsB,OAAA,aAAQ,IAAR,EAAtB;WAAA,MAAA;mBACK,KAAC,CAAA,IAAD,CAAM,MAAN,EAAc,SAAA,GAAA;qBAAG,OAAA,aAAQ,IAAR,EAAH;YAAA,CAAd,EADL;WADgB;QAAA,EAAA;MAAA,CAAA,CAAA,CAAA,IAAA,CAAlB,CAvBA,CAAA;AAAA,MA2BA,YAAY,CAAC,IAAb,CAAkB,CAAA,SAAA,KAAA,GAAA;eAAA,SAAA,GAAA;AAChB,cAAA,IAAA;AAAA,UADkB,8DAClB,CAAA;iBAAA,MAAA,aAAO,IAAP,EADgB;QAAA,EAAA;MAAA,CAAA,CAAA,CAAA,IAAA,CAAlB,CA3BA,CAAA;AA8BA,aAAO,IAAC,CAAA,aAAD,GAAiB,QAAQ,CAAC,OAAjC,CA/BK;IAAA,CA9BP,CAAA;;AAAA,oBA+DA,IAAA,GAAM,SAAE,OAAF,GAAA;;QAAE,UAAU;OAChB;aAAA,gCAAM,CAAC,CAAC,QAAF,CAAW,OAAX,EAAoB;AAAA,QAAA,QAAA,EAAU,IAAC,CAAA,MAAX;OAApB,CAAN,EADI;IAAA,CA/DN,CAAA;;iBAAA;;KADkB,QAAQ,CAAC,QAAQ,CAAC,MAJtC,CAAA;;AAAA,EAuEA,MAAM,CAAC,OAAP,GAAiB,KAvEjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/dist/tails.browser.js b/dist/tails.browser.js new file mode 100644 index 0000000..2674aab --- /dev/null +++ b/dist/tails.browser.js @@ -0,0 +1,2291 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Tails = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0; + }); + }; + })(this), + atLeast: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) >= value; + }); + }; + })(this), + atMost: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) <= value; + }); + }; + })(this), + greaterThan: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) > value; + }); + }; + })(this), + lessThan: (function(_this) { + return function(value) { + return _this.filter(function(model) { + return model.get(key) < value; + }); + }; + })(this) + }; + return query; + } + }; + + Collection.prototype.pluck = function(attribute) { + return new Collection.Plucked(this, { + attribute: attribute + }); + }; + + Collection.prototype.parse = function(response, options) { + var attrs, model, models, _i, _len; + if (!(response instanceof Array)) { + response = [response]; + } + models = []; + for (_i = 0, _len = response.length; _i < _len; _i++) { + attrs = response[_i]; + if (attrs instanceof Backbone.Model) { + models.push(attrs); + break; + } + model = this.model.get(attrs.id); + model.set(attrs); + models.push(model); + } + return models; + }; + + return Collection; + + })(Backbone.Deferred.Collection); + + Collection.Plucked = (function(_super) { + __extends(Plucked, _super); + + function Plucked(collection, options) { + if (options == null) { + options = {}; + } + this.collection = collection; + this.attribute = options.attribute; + this.length = 0; + Plucked.__super__.constructor.call(this, [], options); + this.collection.each((function(_this) { + return function(model) { + return _this.trigger('add', model.get(_this.attribute)); + }; + })(this)); + this.listenTo(collection, "change:" + this.attribute, (function(_this) { + return function(model) { + var previousValue, value; + value = model.get(_this.attribute); + previousValue = model.previous(_this.attribute); + if (previousValue != null) { + _this.trigger('remove', previousValue); + } + if (value != null) { + return _this.trigger('add', value); + } + }; + })(this)); + this.listenTo(collection, 'add', (function(_this) { + return function(model) { + var value; + value = model.get(_this.attribute); + if (value != null) { + _this.trigger('add', value); + } + return _this.length++; + }; + })(this)); + this.listenTo(collection, 'remove', (function(_this) { + return function(model) { + var value; + value = model.get(_this.attribute); + if (value != null) { + _this.trigger('remove', value); + } + return _this.length--; + }; + })(this)); + } + + Plucked.prototype.contains = function(value) { + return __indexOf.call(this.toArray(), value) >= 0; + }; + + Plucked.prototype.include = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.contains.apply(this, args); + }; + + Plucked.prototype.each = function(fn) { + return this.collection.each((function(_this) { + return function(model) { + return fn(model.get(_this.attribute)); + }; + })(this)); + }; + + Plucked.prototype.forEach = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.each.apply(this, args); + }; + + Plucked.prototype.toArray = function() { + var model; + return (function() { + var _i, _len, _ref, _results; + _ref = this.collection.toArray(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + model = _ref[_i]; + _results.push(model.get(this.attribute)); + } + return _results; + }).call(this); + }; + + return Plucked; + + })(Collection); + + Collection.Filtered = (function(_super) { + __extends(Filtered, _super); + + function Filtered(collection, options) { + if (options == null) { + options = {}; + } + this.collection = collection; + this.model = this.collection.model; + this.filter = options.filter; + this.assimilate = options.assimilate; + this.distantiate = options.distantiate; + Filtered.__super__.constructor.call(this, [], options); + this.collection.each((function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } + }; + })(this)); + this.listenTo(this.collection, 'add', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } + }; + })(this)); + this.listenTo(this.collection, 'remove', (function(_this) { + return function(model) { + return _this.remove(model); + }; + })(this)); + this.listenTo(this.collection, 'change', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return _this.add(model); + } else { + return _this.remove(model); + } + }; + })(this)); + this.on('add', (function(_this) { + return function(model) { + if (_this.filter(model)) { + return; + } + if (_this.assimilate == null) { + _this.remove(model); + throw Error("Cannot assimilate model."); + } + _this.assimilate(model); + return _this.collection.add(model); + }; + })(this)); + this.on('remove', (function(_this) { + return function(model) { + if (!_this.collection.contains(model)) { + return; + } + if (!_this.filter(model)) { + return; + } + if (_this.distantiate == null) { + _this.add(model); + throw Error("Cannot distantiate model."); + } + return _this.distantiate(model); + }; + })(this)); + } + + return Filtered; + + })(Collection); + + Collection.Multi = (function(_super) { + __extends(Multi, _super); + + function Multi(collections, options) { + var collection, _i, _len; + if (collections == null) { + collections = []; + } + if (options == null) { + options = {}; + } + this.collections = []; + this.modelCounts = {}; + Multi.__super__.constructor.call(this, [], options); + for (_i = 0, _len = collections.length; _i < _len; _i++) { + collection = collections[_i]; + this.addCollection(collection); + } + } + + Multi.prototype.increment = function(model) { + var _base, _name; + (_base = this.modelCounts)[_name = model.cid] || (_base[_name] = 0); + return ++this.modelCounts[model.cid]; + }; + + Multi.prototype.decrement = function(model) { + var _base, _name; + (_base = this.modelCounts)[_name = model.cid] || (_base[_name] = 0); + return --this.modelCounts[model.cid]; + }; + + Multi.prototype.addCollection = function(collection) { + if (!(collection instanceof Backbone.Collection)) { + return; + } + this.model || (this.model = collection.model); + this.collections.push(collection); + collection.each((function(_this) { + return function(model) { + return _this.increment(model); + }; + })(this)); + this.listenTo(collection, 'add', this.increment); + this.listenTo(collection, 'remove', this.decrement); + return this.trigger('addCollection', collection); + }; + + Multi.prototype.removeCollection = function(collection) { + var index; + if (!(collection instanceof Backbone.Collection)) { + return; + } + index = this.collections.indexOf(collection); + if (!(index >= 0)) { + return; + } + this.collections = this.collections.slice(0, index).concat(this.collections.slice(index + 1, this.collections.length)); + collection.each((function(_this) { + return function(model) { + return _this.decrement(model); + }; + })(this)); + this.stopListening(collection); + return this.trigger('removeCollection', collection); + }; + + return Multi; + + })(Collection); + + Collection.Union = (function(_super) { + __extends(Union, _super); + + function Union() { + return Union.__super__.constructor.apply(this, arguments); + } + + Union.prototype.increment = function(model) { + if (Union.__super__.increment.apply(this, arguments) === 1) { + return this.add(model); + } + }; + + Union.prototype.decrement = function(model) { + if (Union.__super__.decrement.apply(this, arguments) === 0) { + return this.remove(model); + } + }; + + return Union; + + })(Collection.Multi); + + module.exports = Collection; + +}).call(this); + +//# sourceMappingURL=collection.js.map + +},{"./config":7,"./mixable":8,"./model":16}],7:[function(require,module,exports){ +(function() { + module.exports = { + url: 'http://localhost' + }; + +}).call(this); + +//# sourceMappingURL=config.js.map + +},{}],8:[function(require,module,exports){ +(function() { + var Mixable, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, + __slice = [].slice; + + Mixable = { + MixableKeywords: ['included', 'extended', 'constructor', 'Interactions', 'InstanceMethods', 'ClassMethods'], + _include: function(mixin) { + var funcs, key, value, _ref; + if (mixin.InstanceMethods != null) { + funcs = mixin.InstanceMethods; + } else if (mixin.ClassMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this.prototype[key] = value; + } + } + } + return (_ref = funcs.included) != null ? _ref.apply(this) : void 0; + }, + _extend: function(mixin) { + var funcs, key, value, _ref; + if (mixin.ClassMethods != null) { + funcs = mixin.ClassMethods; + } else if (mixin.InstanceMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this[key] = value; + } + } + } + return (_ref = funcs.extended) != null ? _ref.apply(this) : void 0; + }, + include: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._includedMixins) != null ? _ref.klass : void 0) !== this) { + this._includedMixins = _(this._includedMixins).clone() || []; + this._includedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._includedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._includedMixins.push(mixin); + } + this._include(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + _ref1 = this._includedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + return this; + }, + extend: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._extendedMixins) != null ? _ref.klass : void 0) !== this) { + this._extendedMixins = _(this._extendedMixins).clone() || []; + this._extendedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._extendedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._extendedMixins.push(mixin); + } + this._extend(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + _ref1 = this._extendedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + return this; + }, + "with": function(mixin, funcs) { + if (funcs == null) { + funcs = {}; + } + if ((this._includedMixins != null) && __indexOf.call(this._includedMixins, mixin) >= 0) { + return funcs; + } else if ((this._extendedMixins != null) && __indexOf.call(this._extendedMixins, mixin) >= 0) { + return funcs; + } else { + return null; + } + }, + concern: function() { + var mixin, mixins, _i, _len; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + this.include(mixin); + this.extend(mixin); + } + return this; + } + }; + + module.exports = Mixable; + +}).call(this); + +//# sourceMappingURL=mixable.js.map + +},{}],9:[function(require,module,exports){ +(function() { + var Associable, Association, Relation; + + Relation = require('../associations/relation'); + + Association = require('../associations/association'); + + Associable = { + InstanceMethods: { + relations: function() { + var Collection; + Collection = require('../collection'); + if (this._relations == null) { + this._relations = new Collection([], { + model: Relation + }); + } + return this._relations; + } + }, + ClassMethods: { + belongsTo: function(options) { + return this.associate('belongsTo', options); + }, + hasOne: function(options) { + return this.associate('hasOne', options); + }, + hasMany: function(options) { + return this.associate('hasMany', options); + }, + associate: function(type, options) { + var association, attrs, name, to; + name = _(options).keys()[0]; + to = options[name]; + attrs = { + type: type, + from: this, + name: name, + foreignKey: options.foreignKey, + through: options.through, + source: options.source + }; + association = new Association(attrs); + if (to.prototype instanceof Backbone.Model) { + return association.set({ + to: to + }); + } else { + return association.getter({ + to: to + }); + } + }, + associations: function() { + var _ref; + if (!((_ref = this._associations) != null ? _ref.klass = this : void 0)) { + this._associations = Association.all().where({ + from: this + }); + this._associations.klass = this; + } + return this._associations; + }, + extended: function() { + var Collectable, DynamicAttributes, Interceptable; + DynamicAttributes = require('./dynamic_attributes'); + Collectable = require('./collectable'); + Interceptable = require('./interceptable'); + this.concern(DynamicAttributes); + this.concern(Collectable); + this.concern(Interceptable); + return this.before({ + initialize: function() { + return this.constructor.associations().each((function(_this) { + return function(association) { + return association.apply(_this); + }; + })(this)); + } + }); + } + } + }; + + module.exports = Associable; + +}).call(this); + +//# sourceMappingURL=associable.js.map + +},{"../associations/association":1,"../associations/relation":5,"../collection":6,"./collectable":10,"./dynamic_attributes":12,"./interceptable":14}],10:[function(require,module,exports){ +(function() { + var Collectable, Interceptable; + + Interceptable = require('./interceptable'); + + Collectable = { + InstanceMethods: { + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + if ((this.id != null) && (this.constructor.all().get(this.id) != null)) { + throw new Error("Duplicate " + this.constructor.name + " for id " + this.id + "."); + } + return this.constructor.all().add(this); + } + }); + } + }, + ClassMethods: { + all: function() { + var Collection, _ref; + Collection = require('../collection'); + if (((_ref = this._all) != null ? _ref.klass : void 0) !== this) { + this._all = new Collection(null, { + model: this + }); + this._all.klass = this; + } + return this._all; + }, + get: function(id) { + return this.all().get(id) || new this({ + id: id + }); + }, + scope: function(name, options) { + return this[name] = this.all().where(options.where); + } + }, + Interactions: function() { + var Storage; + Storage = require('./storage'); + return { + ClassMethods: this["with"](Storage, { + extended: function() { + return this.all().on('add remove', (function(_this) { + return function(instance) { + if (instance.id != null) { + return _this.store(); + } + }; + })(this)); + } + }) + }; + } + }; + + module.exports = Collectable; + +}).call(this); + +//# sourceMappingURL=collectable.js.map + +},{"../collection":6,"./interceptable":14,"./storage":15}],11:[function(require,module,exports){ +(function() { + var Debug, Interceptable, + __slice = [].slice, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Interceptable = require('./interceptable'); + + Debug = { + InstanceMethods: { + LOG_LEVELS: { + "ERROR": true, + "WARNING": true, + "INFO": false + }, + _excludedMethods: _.union(Object.keys(Interceptable.InstanceMethods), ["constructor", "log", "message", "warn", "error", "info"]), + debug: function() { + return this.LOG_LEVELS.INFO = true; + }, + message: function() { + var line, thing, things, _i, _len; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = "" + (new Date()) + " - "; + for (_i = 0, _len = things.length; _i < _len; _i++) { + thing = things[_i]; + if (thing.constructor.name === "String") { + line += thing + " "; + } else { + line += JSON.stringify(thing) + " "; + } + } + line += "in " + this.constructor.name + "(" + this.id + ")"; + return line; + }, + error: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.ERROR) { + return; + } + line = this.message.apply(this, things); + return console.error(line); + }, + warn: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.WARNING) { + return; + } + line = this.message.apply(this, things); + return console.warn(line); + }, + log: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = this.message.apply(this, things); + return console.log(line); + }, + info: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.INFO) { + return; + } + line = this.message.apply(this, things); + return console.log(line); + }, + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + var args, funcs, key, value, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + this.info("Called function 'initialize' of " + this.constructor.name + " with arguments:", args); + this.on("change", (function(_this) { + return function(event) { + return _this.info("Change of attributes:", event.changedAttributes()); + }; + })(this)); + funcs = (function() { + var _results; + _results = []; + for (key in this) { + value = this[key]; + if (value instanceof Function && __indexOf.call(this._excludedMethods, key) < 0) { + _results.push(key); + } else { + continue; + } + } + return _results; + }).call(this); + _results = []; + for (_i = 0, _len = funcs.length; _i < _len; _i++) { + key = funcs[_i]; + _results.push((function(_this) { + return function(key) { + return _this.after({ + "these": [key], + "do": function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.info("Called function '" + key + "' of " + this.constructor.name + " with arguments:", args); + } + }); + }; + })(this)(key)); + } + return _results; + } + }); + } + } + }; + + module.exports = Debug; + +}).call(this); + +//# sourceMappingURL=debug.js.map + +},{"./interceptable":14}],12:[function(require,module,exports){ +(function() { + var DynamicAttributes, Interceptable; + + Interceptable = require('./interceptable'); + + DynamicAttributes = { + InstanceMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.defineAttribute({ + getter: getters + }); + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.defineAttribute({ + setter: setters + }); + }, + lazy: function(attributes, fn) { + var key, name, _results; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + _results = []; + for (key in attributes) { + fn = attributes[key]; + _results.push((function(_this) { + return function(key, fn) { + _this.getter(key, function() { + return _this.attributes[key] = (_this[fn] || fn).call(_this); + }); + return _this.setter(key, function(value) { + delete _this.attributes[key]; + return _this.attributes[key] = value; + }); + }; + })(this)(key, fn)); + } + return _results; + }, + defineAttribute: function(params) { + var attributes, fn, key, type, _results; + _results = []; + for (type in params) { + attributes = params[type]; + if (type === 'getter' || type === 'setter') { + _results.push((function() { + var _results1; + _results1 = []; + for (key in attributes) { + fn = attributes[key]; + _results1.push((function(_this) { + return function(key, fn) { + var map; + map = Object.getOwnPropertyDescriptor(_this.attributes, key) || { + configurable: true + }; + delete _this.attributes[key]; + delete map.value; + delete map.writable; + if (type === 'getter') { + map.get = function() { + return (_this[fn] || fn).call(_this); + }; + } else if (type === 'setter') { + map.set = function(value) { + var result; + return result = (_this[fn] || fn).call(_this, value); + }; + } + return Object.defineProperty(_this.attributes, key, map); + }; + })(this)(key, fn)); + } + return _results1; + }).call(this)); + } + } + return _results; + } + }, + ClassMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.getter(getters); + } + }); + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.setter(setters); + } + }); + }, + lazy: function(attributes, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.lazy(attributes); + } + }); + }, + extended: function() { + return this.concern(Interceptable); + } + } + }; + + module.exports = DynamicAttributes; + +}).call(this); + +//# sourceMappingURL=dynamic_attributes.js.map + +},{"./interceptable":14}],13:[function(require,module,exports){ +(function() { + var History, Storage; + + Storage = require('./storage'); + + History = { + Interactions: function() { + return { + InstanceMethods: this["with"](Storage, { + diff: function() { + var diff, key, prevAttrs, value, _ref; + diff = {}; + diff.apply = (function(_this) { + return function(context) { + var change, key, type, values; + if (context == null) { + context = _this; + } + for (key in diff) { + change = diff[key]; + for (type in change) { + values = change[type]; + switch (type) { + case "create": + context.set(key, values["value"]); + break; + case "update": + context.set(key, values["new"]); + break; + case "delete": + context.unset(key); + } + } + } + return context; + }; + })(this); + prevAttrs = this.constructor.retrieve(this.id) || {}; + _ref = this.attributes; + for (key in _ref) { + value = _ref[key]; + if (prevAttrs[key] !== this.get(key)) { + if (prevAttrs[key] != null) { + diff[key] = { + "update": { + "old": prevAttrs[key], + "new": this.get(key) + } + }; + } else { + diff[key] = { + "create": { + "value": this.get(key) + } + }; + } + } + } + for (key in prevAttrs) { + value = prevAttrs[key]; + if (!this.has(key)) { + diff[key] = { + "delete": { + "value": value + } + }; + } + } + return diff; + }, + commit: function() { + var key; + key = this.store(this.diff()); + return key; + }, + included: function() { + return this.after({ + initialize: function() { + return this.on("change", this.commit); + } + }); + } + }) + }; + } + }; + + module.exports = History; + +}).call(this); + +//# sourceMappingURL=history.js.map + +},{"./storage":15}],14:[function(require,module,exports){ +(function() { + var Interceptable, + __slice = [].slice; + + Interceptable = { + InstanceMethods: { + before: function(interceptors) { + return this.intercept({ + before: interceptors + }); + }, + after: function(interceptors) { + return this.intercept({ + after: interceptors + }); + }, + intercept: function(params) { + var fn, fns, interceptors, k, key, klass, placement, v, _i, _len, _ref, _results; + klass = this.constructor; + _results = []; + for (placement in params) { + interceptors = params[placement]; + if (!(placement === 'before' || placement === 'after')) { + continue; + } + if (interceptors.these != null) { + _ref = interceptors.these; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + if (typeof key === 'function') { + for (k in this) { + v = this[k]; + if (key === v) { + key = k; + break; + } + } + } + interceptors[key] = interceptors["do"]; + } + } + interceptors = _(interceptors).omit('these', 'do'); + _results.push((function() { + var _results1; + _results1 = []; + for (key in interceptors) { + fns = interceptors[key]; + if (!_(fns).isArray()) { + fns = [fns]; + } + _results1.push((function() { + var _j, _len1, _results2; + _results2 = []; + for (_j = 0, _len1 = fns.length; _j < _len1; _j++) { + fn = fns[_j]; + _results2.push((function(_this) { + return function(key, fn) { + var after, before, interceptable, prev, _ref1, _ref2, _ref3, _ref4; + if ((_this.hasOwnProperty(key) || klass.prototype.hasOwnProperty(key)) && !((_this[key].before != null) || (_this[key].after != null))) { + interceptable = _this[key]; + return _this[key] = function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (placement === 'before') { + (this[fn] || fn).apply(this, args); + } + ret = interceptable.apply(this, args); + if (placement === 'after') { + (this[fn] || fn).apply(this, args); + } + return ret; + }; + } else { + before = ((_ref1 = _this[key]) != null ? _ref1.klass : void 0) === klass ? (_ref2 = _this[key]) != null ? _ref2.before : void 0 : void 0; + after = ((_ref3 = _this[key]) != null ? _ref3.klass : void 0) === klass ? (_ref4 = _this[key]) != null ? _ref4.after : void 0 : void 0; + if (placement === 'before') { + prev = before; + before = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (prev != null) { + prev.apply(this, args); + } + return (this[fn] || fn).apply(this, args); + }; + } else if (placement === 'after') { + prev = after; + after = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + (this[fn] || fn).apply(this, args); + return prev != null ? prev.apply(this, args) : void 0; + }; + } + return Object.defineProperty(_this, key, { + configurable: true, + set: function(interceptable) { + return Object.defineProperty(this, key, { + writable: true, + value: function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + ret = interceptable.apply(this, args); + if (after != null) { + after.apply(this, args); + } + return ret; + } + }); + }, + get: function() { + var interceptor; + interceptor = function() { + var args, ret, superFn, _ref5; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + superFn = (_ref5 = this.constructor.__super__) != null ? _ref5[key] : void 0; + if ((superFn != null ? superFn.klass : void 0) !== klass) { + ret = superFn != null ? superFn.apply(this, args) : void 0; + } + if (after != null) { + after.apply(this, args); + } + return ret; + }; + interceptor.before = before; + interceptor.after = after; + interceptor.klass = klass; + return interceptor; + } + }); + } + }; + })(this)(key, fn)); + } + return _results2; + }).call(this)); + } + return _results1; + }).call(this)); + } + return _results; + } + }, + ClassMethods: { + before: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.before(interceptors.call(this)); + } + }); + } else { + return this.prototype.before(interceptors); + } + }, + after: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.after(interceptors.call(this)); + } + }); + } else { + return this.prototype.after(interceptors); + } + } + } + }; + + module.exports = Interceptable; + +}).call(this); + +//# sourceMappingURL=interceptable.js.map + +},{}],15:[function(require,module,exports){ +(function() { + var Collectable, Debug, Hash, Interceptable, Storage; + + Interceptable = require('./interceptable'); + + Hash = require('../utils/hash'); + + Debug = require('./debug'); + + Collectable = require('./collectable'); + + Storage = { + InstanceMethods: { + storage: function() { + return this.constructor.storage(); + }, + indexRoot: function() { + return this.constructor.indexRoot(); + }, + store: function(data) { + return this.constructor.store(this, data); + }, + retrieve: function(hash) { + return _.defaults(this.attributes, this.constructor.retrieve(this.id, hash)); + }, + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + this.on("sync", this.store); + this.retrieve(); + return this.store(); + } + }); + } + }, + ClassMethods: { + storage: function() { + return localStorage; + }, + toJSON: function(obj) { + return JSON.stringify(obj); + }, + indexRoot: function() { + return inflection.transform(this.name, ['underscore', 'pluralize']); + }, + store: function(instance, data) { + var indexRoot, json, key, _ref; + if (!((instance != null) && (instance.id != null))) { + return; + } + indexRoot = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + key = "" + indexRoot + "/" + instance.id; + if (data != null) { + key += "/" + Hash(this.toJSON(data)); + json = this.toJSON({ + "instance": instance, + "data": data + }); + } else { + json = this.toJSON(instance); + } + this.storage().setItem(key, json); + return key; + }, + retrieve: function(id, hash) { + var ids, indexRoot, json, key, _i, _len, _ref; + indexRoot = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + if (id != null) { + key = "" + indexRoot + "/" + id; + if (hash != null) { + key += "/" + hash; + } + json = this.storage().getItem(key); + if (json != null) { + return JSON.parse(json); + } + } else { + json = this.storage().getItem(Hash(indexRoot)); + ids = JSON.parse(json); + if (json != null) { + for (_i = 0, _len = ids.length; _i < _len; _i++) { + id = ids[_i]; + this.retrieve(id); + } + } + return ids; + } + } + }, + Interactions: function() { + return { + InstanceMethods: this["with"](Debug, { + included: (function(_this) { + return function() { + return _this.after({ + initialize: function() { + console.log(this.toJSON(this.name)); + return this.after({ + store: function() { + return this.log("Stored instances", this.constructor.all().pluck("id")); + } + }); + } + }); + }; + })(this) + }), + ClassMethods: this["with"](Collectable, { + indexRoot: function() { + var _ref; + return (_ref = typeof this.urlRoot === "function" ? this.urlRoot() : void 0) != null ? _ref : this.urlRoot; + }, + extended: function() { + return this.after({ + store: function() { + var json, key, _ref; + key = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; + json = this.toJSON(this.constructor.all().pluck("id")); + return this.constructor.storage().setItem(key, json); + } + }); + } + }) + }; + } + }; + + module.exports = Storage; + +}).call(this); + +//# sourceMappingURL=storage.js.map + +},{"../utils/hash":19,"./collectable":10,"./debug":11,"./interceptable":14}],16:[function(require,module,exports){ +(function() { + var Associable, Mixable, Model, config, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice; + + Mixable = require('./mixable'); + + Associable = require('./mixins/associable'); + + config = require('./config'); + + Model = (function(_super) { + __extends(Model, _super); + + function Model() { + return Model.__super__.constructor.apply(this, arguments); + } + + _.extend(Model, Mixable); + + Model.concern(Associable); + + Model.prototype.syncedAt = 0; + + Model.prototype.initialize = function(attrs, options) { + var _ref; + if (attrs == null) { + attrs = {}; + } + if (options == null) { + options = {}; + } + this.parent = options.parent || this.parent || ((_ref = this.collection) != null ? _ref.parent : void 0); + this.synced = options.synced || false; + this.on('change', (function(_this) { + return function(model) { + return _this.synced = false; + }; + })(this)); + this.on('sync', (function(_this) { + return function() { + _this.synced = true; + return _this.syncedAt = Date.now(); + }; + })(this)); + return Model.__super__.initialize.apply(this, arguments); + }; + + Model.prototype.urlRoot = function() { + return inflection.transform(this.constructor.name || this.constructor.toString().match(/^function\s*([^\s(]+)/)[1], ['underscore', 'pluralize']); + }; + + Model.prototype.url = function() { + var base, format, id, root, url, _ref, _ref1; + base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || config.url; + root = (typeof this.urlRoot === "function" ? this.urlRoot() : void 0) || this.urlRoot; + id = this.id ? "/" + this.id : ''; + format = this.format != null ? '.' + ((typeof this.format === "function" ? this.format() : void 0) || this.format) : ''; + url = "" + base + "/" + root + id + format; + return url; + }; + + Model.prototype.fetch = function(options) { + var deferred, fetchPromise, reject, resolve; + if (options == null) { + options = {}; + } + if (!options.force) { + if (this.syncing) { + return this._fetchPromise; + } else if (this.synced) { + deferred = Q.defer(); + deferred.resolve(); + return deferred.promise; + } + } + options.dataType || (options.dataType = this.format); + fetchPromise = Model.__super__.fetch.call(this, options); + this.synced = false; + this.syncing = true; + deferred = Q.defer(); + resolve = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.resolve.apply(deferred, args); + }; + })(this); + reject = (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + _this.syncing = false; + return deferred.reject.apply(deferred, args); + }; + })(this); + fetchPromise.then((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (_this.synced) { + return resolve.apply(null, args); + } else { + return _this.once('sync', function() { + return resolve.apply(null, args); + }); + } + }; + })(this)); + fetchPromise.fail((function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return reject.apply(null, args); + }; + })(this)); + return this._fetchPromise = deferred.promise; + }; + + Model.prototype.save = function(options) { + if (options == null) { + options = {}; + } + return Model.__super__.save.call(this, _.defaults(options, { + dataType: this.format + })); + }; + + return Model; + + })(Backbone.Deferred.Model); + + module.exports = Model; + +}).call(this); + +//# sourceMappingURL=model.js.map + +},{"./config":7,"./mixable":8,"./mixins/associable":9}],17:[function(require,module,exports){ +(function() { + var Associable, Association, BelongsToRelation, Collectable, Collection, Debug, DynamicAttributes, HasManyRelation, HasOneRelation, Hash, History, Interceptable, Mixable, Model, Relation, Storage, Tails, Template, View, config; + + require('./utils/rivets-tails'); + + Hash = require('./utils/hash'); + + Mixable = require('./mixable'); + + Interceptable = require('./mixins/interceptable'); + + Debug = require('./mixins/debug'); + + DynamicAttributes = require('./mixins/dynamic_attributes'); + + Collectable = require('./mixins/collectable'); + + Associable = require('./mixins/associable'); + + Storage = require('./mixins/storage'); + + History = require('./mixins/history'); + + Collection = require('./collection'); + + Association = require('./associations/association'); + + Relation = require('./associations/relation'); + + BelongsToRelation = require('./associations/belongs_to_relation'); + + HasOneRelation = require('./associations/has_one_relation'); + + HasManyRelation = require('./associations/has_many_relation'); + + Model = require('./model'); + + Template = require('./template'); + + View = require('./view'); + + config = require('./config'); + + Tails = { + Mixins: {}, + Utils: {}, + Associations: {}, + Models: {}, + Views: {} + }; + + Tails.Utils = { + Hash: Hash + }; + + Tails.Mixable = Mixable; + + Tails.Mixins = { + Interceptable: Interceptable, + Collectable: Collectable, + Associable: Associable, + Debug: Debug, + DynamicAttributes: DynamicAttributes, + Storage: Storage, + History: History + }; + + Tails.Collection = Collection; + + Tails.Associations = { + Relation: Relation, + Association: Association, + BelongsToRelation: BelongsToRelation, + HasOneRelation: HasOneRelation, + HasManyRelation: HasManyRelation + }; + + Tails.Model = Model; + + Tails.View = View; + + Tails.Template = Template; + + Tails.config = config; + + module.exports = Tails; + +}).call(this); + +//# sourceMappingURL=tails.js.map + +},{"./associations/association":1,"./associations/belongs_to_relation":2,"./associations/has_many_relation":3,"./associations/has_one_relation":4,"./associations/relation":5,"./collection":6,"./config":7,"./mixable":8,"./mixins/associable":9,"./mixins/collectable":10,"./mixins/debug":11,"./mixins/dynamic_attributes":12,"./mixins/history":13,"./mixins/interceptable":14,"./mixins/storage":15,"./model":16,"./template":18,"./utils/hash":19,"./utils/rivets-tails":20,"./view":21}],18:[function(require,module,exports){ +(function() { + var Collectable, Model, Template, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Collectable = require('./mixins/collectable'); + + Model = require('./model'); + + Template = (function(_super) { + __extends(Template, _super); + + function Template() { + return Template.__super__.constructor.apply(this, arguments); + } + + Template.concern(Collectable); + + Template.prototype.urlRoot = 'assets'; + + Template.prototype.format = 'html'; + + Template.prototype.bind = function(view) { + return this.fetch({ + parse: true + }).then((function(_this) { + return function() { + var $el; + $el = $(_this.get('html')).clone(); + rivets.bind($el, view); + return $el; + }; + })(this)); + }; + + Template.prototype.parse = function(response, options) { + return { + html: response + }; + }; + + return Template; + + })(Model); + + module.exports = Collectable; + +}).call(this); + +//# sourceMappingURL=template.js.map + +},{"./mixins/collectable":10,"./model":16}],19:[function(require,module,exports){ +(function() { + var Hash; + + Hash = function(string) { + var char, hash, i, _i, _ref; + hash = 0; + if (string.length === 0) { + return hash; + } + for (i = _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + char = string.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; + } + return hash; + }; + + module.exports = Hash; + +}).call(this); + +//# sourceMappingURL=hash.js.map + +},{}],20:[function(require,module,exports){ +(function() { + if (typeof rivets !== "undefined" && rivets !== null) { + rivets.adapters[':'] = { + subscribe: function(obj, keypath, callback) { + if (obj instanceof Backbone.Collection) { + obj.on('add remove reset', callback); + } + return obj.on('change:' + keypath, callback); + }, + unsubscribe: function(obj, keypath, callback) { + if (obj instanceof Backbone.Collection) { + obj.off('add remove reset', callback); + } + return obj.off('change:' + keypath, callback); + }, + read: function(obj, keypath) { + if (obj instanceof Backbone.Collection) { + return obj.models; + } else { + return obj.get(keypath); + } + }, + publish: function(obj, keypath, value) { + return obj.set(keypath, value); + } + }; + } + +}).call(this); + +//# sourceMappingURL=rivets-tails.js.map + +},{}],21:[function(require,module,exports){ +(function() { + var Mixable, Template, View, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Mixable = require('./mixable'); + + Template = require('./template'); + + View = (function(_super) { + __extends(View, _super); + + function View() { + return View.__super__.constructor.apply(this, arguments); + } + + _.extend(View, Mixable); + + View.prototype.initialize = function(options) { + if (options == null) { + options = {}; + } + if (this.template.constructor === String) { + this.template = Template.get(this.template); + } + this.template.bind(this).then((function(_this) { + return function($el) { + _this.setElement($el); + return _this.render(); + }; + })(this)); + return View.__super__.initialize.call(this, options); + }; + + View.prototype.render = function() { + return this.delegateEvents(); + }; + + View.prototype.setView = function(view) { + this.view = view; + return this.view.render(); + }; + + return View; + + })(Backbone.View); + + module.exports = View; + +}).call(this); + +//# sourceMappingURL=view.js.map + +},{"./mixable":8,"./template":18}]},{},[17])(17) +}); \ No newline at end of file diff --git a/dist/tails.browser.min.js b/dist/tails.browser.min.js new file mode 100644 index 0000000..a1f873c --- /dev/null +++ b/dist/tails.browser.min.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Tails=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb;b++)if(b in this&&this[b]===a)return b;return-1};d=a("./mixable"),e=a("./model"),f=a("./config"),c=function(a){function b(a,c){null==a&&(a=[]),null==c&&(c={}),this.model=c.model||this.model||e,this.parent=c.parent||this.parent,this.synced=c.synced||!1,this.on("change",function(a){return function(){return a.synced=!1}}(this)),this.on("sync",function(a){return function(){return a.synced=!0,a.syncedAt=Date.now()}}(this)),b.__super__.constructor.apply(this,arguments)}return h(b,a),_.extend(b,d),b.prototype.syncedAt=0,b.prototype.urlRoot=function(){return inflection.transform(this.model.name||this.model.toString().match(/^function\s*([^\s(]+)/)[1],["underscore","pluralize"])},b.prototype.url=function(){var a,b,c,d,e,g;return a=(null!=(e=this.parent)&&"function"==typeof e.url?e.url():void 0)||(null!=(g=this.parent)?g.url:void 0)||f.url,c=("function"==typeof this.urlRoot?this.urlRoot():void 0)||this.urlRoot,b=null!=this.format?"."+(("function"==typeof this.format?this.format():void 0)||this.format):"",d=""+a+"/"+c+b},b.prototype.fetch=function(a){var c,d,e,f;if(null==a&&(a={}),!a.force){if(this.syncing)return this._fetchPromise;if(this.synced)return c=Q.defer(),c.resolve(),c.promise}return a.dataType||(a.dataType=this.format),d=b.__super__.fetch.call(this,a),this.synced=!1,this.syncing=!0,c=Q.defer(),f=function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.syncing=!1,c.resolve.apply(c,b)}}(this),e=function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.syncing=!1,c.reject.apply(c,b)}}(this),d.then(function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.synced?f.apply(null,b):a.once("sync",function(){return f.apply(null,b)})}}(this)),d.fail(function(){return function(){var a;return a=1<=arguments.length?i.call(arguments,0):[],e.apply(null,a)}}(this)),this._fetchPromise=c.promise},b.prototype.filter=function(a){return new b.Filtered(this,{filter:a})},b.prototype.where=function(a,c){var d,e,f,g,h;return null!=c?b.__super__.where.call(this,a,c):"object"==typeof a?(f=function(b){var c,d;for(c in a)if(d=a[c],b.get(c)!==d)return!1;return!0},d=function(b){var c,d,e;e=[];for(c in a)d=a[c],e.push(b.set(c,d));return e},e=function(b){var c,d,e;e=[];for(c in a)d=a[c],e.push(b.unset(c));return e},new b.Filtered(this,{filter:f,assimilate:d,distantiate:e})):"string"==typeof a?(g=a,h={is:function(a){return function(b){var c,d,e,f;return(c={})[g]=b,(d=(e=(f=a._where||(a._where={}))[g]||(f[g]={})).is||(e.is={}))[b]||(d[b]=a.where(c))}}(this),"in":function(a){return function(b){return a.filter(function(a){var c;return c=a.get(g),j.call(b,c)>=0})}}(this),atLeast:function(a){return function(b){return a.filter(function(a){return a.get(g)>=b})}}(this),atMost:function(a){return function(b){return a.filter(function(a){return a.get(g)<=b})}}(this),greaterThan:function(a){return function(b){return a.filter(function(a){return a.get(g)>b})}}(this),lessThan:function(a){return function(b){return a.filter(function(a){return a.get(g)e;e++){if(b=a[e],b instanceof Backbone.Model){d.push(b);break}c=this.model.get(b.id),c.set(b),d.push(c)}return d},b}(Backbone.Deferred.Collection),c.Plucked=function(a){function b(a,c){null==c&&(c={}),this.collection=a,this.attribute=c.attribute,this.length=0,b.__super__.constructor.call(this,[],c),this.collection.each(function(a){return function(b){return a.trigger("add",b.get(a.attribute))}}(this)),this.listenTo(a,"change:"+this.attribute,function(a){return function(b){var c,d;return d=b.get(a.attribute),c=b.previous(a.attribute),null!=c&&a.trigger("remove",c),null!=d?a.trigger("add",d):void 0}}(this)),this.listenTo(a,"add",function(a){return function(b){var c;return c=b.get(a.attribute),null!=c&&a.trigger("add",c),a.length++}}(this)),this.listenTo(a,"remove",function(a){return function(b){var c;return c=b.get(a.attribute),null!=c&&a.trigger("remove",c),a.length--}}(this))}return h(b,a),b.prototype.contains=function(a){return j.call(this.toArray(),a)>=0},b.prototype.include=function(){var a;return a=1<=arguments.length?i.call(arguments,0):[],this.contains.apply(this,a)},b.prototype.each=function(a){return this.collection.each(function(b){return function(c){return a(c.get(b.attribute))}}(this))},b.prototype.forEach=function(){var a;return a=1<=arguments.length?i.call(arguments,0):[],this.each.apply(this,a)},b.prototype.toArray=function(){var a;return function(){var b,c,d,e;for(d=this.collection.toArray(),e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.get(this.attribute));return e}.call(this)},b}(c),c.Filtered=function(a){function b(a,c){null==c&&(c={}),this.collection=a,this.model=this.collection.model,this.filter=c.filter,this.assimilate=c.assimilate,this.distantiate=c.distantiate,b.__super__.constructor.call(this,[],c),this.collection.each(function(a){return function(b){return a.filter(b)?a.add(b):void 0}}(this)),this.listenTo(this.collection,"add",function(a){return function(b){return a.filter(b)?a.add(b):void 0}}(this)),this.listenTo(this.collection,"remove",function(a){return function(b){return a.remove(b)}}(this)),this.listenTo(this.collection,"change",function(a){return function(b){return a.filter(b)?a.add(b):a.remove(b)}}(this)),this.on("add",function(a){return function(b){if(!a.filter(b)){if(null==a.assimilate)throw a.remove(b),Error("Cannot assimilate model.");return a.assimilate(b),a.collection.add(b)}}}(this)),this.on("remove",function(a){return function(b){if(a.collection.contains(b)&&a.filter(b)){if(null==a.distantiate)throw a.add(b),Error("Cannot distantiate model.");return a.distantiate(b)}}}(this))}return h(b,a),b}(c),c.Multi=function(a){function b(a,c){var d,e,f;for(null==a&&(a=[]),null==c&&(c={}),this.collections=[],this.modelCounts={},b.__super__.constructor.call(this,[],c),e=0,f=a.length;f>e;e++)d=a[e],this.addCollection(d)}return h(b,a),b.prototype.increment=function(a){var b,c;return(b=this.modelCounts)[c=a.cid]||(b[c]=0),++this.modelCounts[a.cid]},b.prototype.decrement=function(a){var b,c;return(b=this.modelCounts)[c=a.cid]||(b[c]=0),--this.modelCounts[a.cid]},b.prototype.addCollection=function(a){return a instanceof Backbone.Collection?(this.model||(this.model=a.model),this.collections.push(a),a.each(function(a){return function(b){return a.increment(b)}}(this)),this.listenTo(a,"add",this.increment),this.listenTo(a,"remove",this.decrement),this.trigger("addCollection",a)):void 0},b.prototype.removeCollection=function(a){var b;if(a instanceof Backbone.Collection&&(b=this.collections.indexOf(a),b>=0))return this.collections=this.collections.slice(0,b).concat(this.collections.slice(b+1,this.collections.length)),a.each(function(a){return function(b){return a.decrement(b)}}(this)),this.stopListening(a),this.trigger("removeCollection",a)},b}(c),c.Union=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return h(b,a),b.prototype.increment=function(a){return 1===b.__super__.increment.apply(this,arguments)?this.add(a):void 0},b.prototype.decrement=function(a){return 0===b.__super__.decrement.apply(this,arguments)?this.remove(a):void 0},b}(c.Multi),b.exports=c}).call(this)},{"./config":7,"./mixable":8,"./model":16}],7:[function(a,b){(function(){b.exports={url:"http://localhost"}}).call(this)},{}],8:[function(a,b){(function(){var a,c=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},d=[].slice;a={MixableKeywords:["included","extended","constructor","Interactions","InstanceMethods","ClassMethods"],_include:function(a){var b,d,e,f;if(null!=a.InstanceMethods)b=a.InstanceMethods;else{if(null!=a.ClassMethods)return;b=a}for(d in b)e=b[d],c.call(this.MixableKeywords,d)<0&&null!=e&&(this.prototype[d]=e);return null!=(f=b.included)?f.apply(this):void 0},_extend:function(a){var b,d,e,f;if(null!=a.ClassMethods)b=a.ClassMethods;else{if(null!=a.InstanceMethods)return;b=a}for(d in b)e=b[d],c.call(this.MixableKeywords,d)<0&&null!=e&&(this[d]=e);return null!=(f=b.extended)?f.apply(this):void 0},include:function(){var a,b,e,f,g,h,i,j,k;for(e=1<=arguments.length?d.call(arguments,0):[],(null!=(j=this._includedMixins)?j.klass:void 0)!==this&&(this._includedMixins=_(this._includedMixins).clone()||[],this._includedMixins.klass=this),f=0,h=e.length;h>f;f++)b=e[f],c.call(this._includedMixins,b)>=0||(null!=b&&this._includedMixins.push(b),this._include(b),null!=b.Interactions&&(a=b.Interactions.apply(this),null!=a&&this._include(a)));for(k=this._includedMixins,g=0,i=k.length;i>g;g++)b=k[g],null!=b.Interactions&&(a=b.Interactions.apply(this),null!=a&&this._include(a));return this},extend:function(){var a,b,e,f,g,h,i,j,k;for(e=1<=arguments.length?d.call(arguments,0):[],(null!=(j=this._extendedMixins)?j.klass:void 0)!==this&&(this._extendedMixins=_(this._extendedMixins).clone()||[],this._extendedMixins.klass=this),f=0,h=e.length;h>f;f++)b=e[f],c.call(this._extendedMixins,b)>=0||(null!=b&&this._extendedMixins.push(b),this._extend(b),null!=b.Interactions&&(a=b.Interactions.apply(this),null!=a&&this._extend(a)));for(k=this._extendedMixins,g=0,i=k.length;i>g;g++)b=k[g],null!=b.Interactions&&(a=b.Interactions.apply(this),null!=a&&this._extend(a));return this},"with":function(a,b){return null==b&&(b={}),null!=this._includedMixins&&c.call(this._includedMixins,a)>=0?b:null!=this._extendedMixins&&c.call(this._extendedMixins,a)>=0?b:null},concern:function(){var a,b,c,e;for(b=1<=arguments.length?d.call(arguments,0):[],c=0,e=b.length;e>c;c++)a=b[c],this.include(a),this.extend(a);return this}},b.exports=a}).call(this)},{}],9:[function(a,b){(function(){var c,d,e;e=a("../associations/relation"),d=a("../associations/association"),c={InstanceMethods:{relations:function(){var b;return b=a("../collection"),null==this._relations&&(this._relations=new b([],{model:e})),this._relations}},ClassMethods:{belongsTo:function(a){return this.associate("belongsTo",a)},hasOne:function(a){return this.associate("hasOne",a)},hasMany:function(a){return this.associate("hasMany",a)},associate:function(a,b){var c,e,f,g;return f=_(b).keys()[0],g=b[f],e={type:a,from:this,name:f,foreignKey:b.foreignKey,through:b.through,source:b.source},c=new d(e),g.prototype instanceof Backbone.Model?c.set({to:g}):c.getter({to:g})},associations:function(){var a;return(null!=(a=this._associations)?a.klass=this:void 0)||(this._associations=d.all().where({from:this}),this._associations.klass=this),this._associations},extended:function(){var b,c,d;return c=a("./dynamic_attributes"),b=a("./collectable"),d=a("./interceptable"),this.concern(c),this.concern(b),this.concern(d),this.before({initialize:function(){return this.constructor.associations().each(function(a){return function(b){return b.apply(a)}}(this))}})}}},b.exports=c}).call(this)},{"../associations/association":1,"../associations/relation":5,"../collection":6,"./collectable":10,"./dynamic_attributes":12,"./interceptable":14}],10:[function(a,b){(function(){var c,d;d=a("./interceptable"),c={InstanceMethods:{included:function(){return this.concern(d),this.after({initialize:function(){if(null!=this.id&&null!=this.constructor.all().get(this.id))throw new Error("Duplicate "+this.constructor.name+" for id "+this.id+".");return this.constructor.all().add(this)}})}},ClassMethods:{all:function(){var b,c;return b=a("../collection"),(null!=(c=this._all)?c.klass:void 0)!==this&&(this._all=new b(null,{model:this}),this._all.klass=this),this._all},get:function(a){return this.all().get(a)||new this({id:a})},scope:function(a,b){return this[a]=this.all().where(b.where)}},Interactions:function(){var b;return b=a("./storage"),{ClassMethods:this["with"](b,{extended:function(){return this.all().on("add remove",function(a){return function(b){return null!=b.id?a.store():void 0}}(this))}})}}},b.exports=c}).call(this)},{"../collection":6,"./interceptable":14,"./storage":15}],11:[function(a,b){(function(){var c,d,e=[].slice,f=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};d=a("./interceptable"),c={InstanceMethods:{LOG_LEVELS:{ERROR:!0,WARNING:!0,INFO:!1},_excludedMethods:_.union(Object.keys(d.InstanceMethods),["constructor","log","message","warn","error","info"]),debug:function(){return this.LOG_LEVELS.INFO=!0},message:function(){var a,b,c,d,f;for(c=1<=arguments.length?e.call(arguments,0):[],a=""+new Date+" - ",d=0,f=c.length;f>d;d++)b=c[d],a+="String"===b.constructor.name?b+" ":JSON.stringify(b)+" ";return a+="in "+this.constructor.name+"("+this.id+")"},error:function(){var a,b;return b=1<=arguments.length?e.call(arguments,0):[],this.LOG_LEVELS.ERROR?(a=this.message.apply(this,b),console.error(a)):void 0},warn:function(){var a,b;return b=1<=arguments.length?e.call(arguments,0):[],this.LOG_LEVELS.WARNING?(a=this.message.apply(this,b),console.warn(a)):void 0},log:function(){var a,b;return b=1<=arguments.length?e.call(arguments,0):[],a=this.message.apply(this,b),console.log(a)},info:function(){var a,b;return b=1<=arguments.length?e.call(arguments,0):[],this.LOG_LEVELS.INFO?(a=this.message.apply(this,b),console.log(a)):void 0},included:function(){return this.concern(d),this.after({initialize:function(){var a,b,c,d,g,h,i;for(a=1<=arguments.length?e.call(arguments,0):[],this.info("Called function 'initialize' of "+this.constructor.name+" with arguments:",a),this.on("change",function(a){return function(b){return a.info("Change of attributes:",b.changedAttributes())}}(this)),b=function(){var a;a=[];for(c in this)d=this[c],d instanceof Function&&f.call(this._excludedMethods,c)<0&&a.push(c);return a}.call(this),i=[],g=0,h=b.length;h>g;g++)c=b[g],i.push(function(a){return function(b){return a.after({these:[b],"do":function(){var a;return a=1<=arguments.length?e.call(arguments,0):[],this.info("Called function '"+b+"' of "+this.constructor.name+" with arguments:",a)}})}}(this)(c));return i}})}}},b.exports=c}).call(this)},{"./interceptable":14}],12:[function(a,b){(function(){var c,d;d=a("./interceptable"),c={InstanceMethods:{getter:function(a,b){var c;return null==b&&(b=null),"string"==typeof a&&null!=b&&(c=a,(a={})[c]=b),this.defineAttribute({getter:a})},setter:function(a,b){var c;return null==b&&(b=null),"string"==typeof a&&null!=b&&(c=a,(a={})[c]=b),this.defineAttribute({setter:a})},lazy:function(a,b){var c,d,e;null==b&&(b=null),"string"==typeof a&&null!=b&&(d=a,(a={})[d]=b),e=[];for(c in a)b=a[c],e.push(function(a){return function(b,c){return a.getter(b,function(){return a.attributes[b]=(a[c]||c).call(a)}),a.setter(b,function(c){return delete a.attributes[b],a.attributes[b]=c})}}(this)(c,b));return e},defineAttribute:function(a){var b,c,d,e,f;f=[];for(e in a)b=a[e],("getter"===e||"setter"===e)&&f.push(function(){var a;a=[];for(d in b)c=b[d],a.push(function(a){return function(b,c){var d;return d=Object.getOwnPropertyDescriptor(a.attributes,b)||{configurable:!0},delete a.attributes[b],delete d.value,delete d.writable,"getter"===e?d.get=function(){return(a[c]||c).call(a)}:"setter"===e&&(d.set=function(b){var d;return d=(a[c]||c).call(a,b)}),Object.defineProperty(a.attributes,b,d)}}(this)(d,c));return a}.call(this));return f}},ClassMethods:{getter:function(a,b){var c;return null==b&&(b=null),"string"==typeof a&&null!=b&&(c=a,(a={})[c]=b),this.before({initialize:function(){return this.getter(a)}})},setter:function(a,b){var c;return null==b&&(b=null),"string"==typeof a&&null!=b&&(c=a,(a={})[c]=b),this.before({initialize:function(){return this.setter(a)}})},lazy:function(a,b){var c;return null==b&&(b=null),"string"==typeof a&&null!=b&&(c=a,(a={})[c]=b),this.before({initialize:function(){return this.lazy(a)}})},extended:function(){return this.concern(d)}}},b.exports=c}).call(this)},{"./interceptable":14}],13:[function(a,b){(function(){var c,d;d=a("./storage"),c={Interactions:function(){return{InstanceMethods:this["with"](d,{diff:function(){var a,b,c,d,e;a={},a.apply=function(b){return function(c){var d,e,f,g;null==c&&(c=b);for(e in a){d=a[e];for(f in d)switch(g=d[f],f){case"create":c.set(e,g.value);break;case"update":c.set(e,g["new"]);break;case"delete":c.unset(e)}}return c}}(this),c=this.constructor.retrieve(this.id)||{},e=this.attributes;for(b in e)d=e[b],c[b]!==this.get(b)&&(a[b]=null!=c[b]?{update:{old:c[b],"new":this.get(b)}}:{create:{value:this.get(b)}});for(b in c)d=c[b],this.has(b)||(a[b]={"delete":{value:d}});return a},commit:function(){var a;return a=this.store(this.diff())},included:function(){return this.after({initialize:function(){return this.on("change",this.commit)}})}})}}},b.exports=c}).call(this)},{"./storage":15}],14:[function(a,b){(function(){var a,c=[].slice;a={InstanceMethods:{before:function(a){return this.intercept({before:a})},after:function(a){return this.intercept({after:a})},intercept:function(a){var b,d,e,f,g,h,i,j,k,l,m,n;h=this.constructor,n=[];for(i in a)if(e=a[i],"before"===i||"after"===i){if(null!=e.these)for(m=e.these,k=0,l=m.length;l>k;k++){if(g=m[k],"function"==typeof g)for(f in this)if(j=this[f],g===j){g=f;break}e[g]=e["do"]}e=_(e).omit("these","do"),n.push(function(){var a;a=[];for(g in e)d=e[g],_(d).isArray()||(d=[d]),a.push(function(){var a,e,f;for(f=[],a=0,e=d.length;e>a;a++)b=d[a],f.push(function(a){return function(b,d){var e,f,g,j,k,l,m,n;return(a.hasOwnProperty(b)||h.prototype.hasOwnProperty(b))&&null==a[b].before&&null==a[b].after?(g=a[b],a[b]=function(){var a,b;return a=1<=arguments.length?c.call(arguments,0):[],"before"===i&&(this[d]||d).apply(this,a),b=g.apply(this,a),"after"===i&&(this[d]||d).apply(this,a),b}):(f=(null!=(k=a[b])?k.klass:void 0)===h&&null!=(l=a[b])?l.before:void 0,e=(null!=(m=a[b])?m.klass:void 0)===h&&null!=(n=a[b])?n.after:void 0,"before"===i?(j=f,f=function(){var a;return a=1<=arguments.length?c.call(arguments,0):[],null!=j&&j.apply(this,a),(this[d]||d).apply(this,a)}):"after"===i&&(j=e,e=function(){var a;return a=1<=arguments.length?c.call(arguments,0):[],(this[d]||d).apply(this,a),null!=j?j.apply(this,a):void 0}),Object.defineProperty(a,b,{configurable:!0,set:function(a){return Object.defineProperty(this,b,{writable:!0,value:function(){var b,d;return b=1<=arguments.length?c.call(arguments,0):[],null!=f&&f.apply(this,b),d=a.apply(this,b),null!=e&&e.apply(this,b),d}})},get:function(){var a;return a=function(){var a,d,g,i;return a=1<=arguments.length?c.call(arguments,0):[],null!=f&&f.apply(this,a),g=null!=(i=this.constructor.__super__)?i[b]:void 0,(null!=g?g.klass:void 0)!==h&&(d=null!=g?g.apply(this,a):void 0),null!=e&&e.apply(this,a),d},a.before=f,a.after=e,a.klass=h,a}}))}}(this)(g,b));return f}.call(this));return a}.call(this))}return n}},ClassMethods:{before:function(a){return null!=("function"==typeof a?a():void 0)?this.before({initialize:function(){return this.before(a.call(this))}}):this.prototype.before(a)},after:function(a){return null!=("function"==typeof a?a():void 0)?this.before({initialize:function(){return this.after(a.call(this))}}):this.prototype.after(a)}}},b.exports=a}).call(this)},{}],15:[function(a,b){(function(){var c,d,e,f,g;f=a("./interceptable"),e=a("../utils/hash"),d=a("./debug"),c=a("./collectable"),g={InstanceMethods:{storage:function(){return this.constructor.storage()},indexRoot:function(){return this.constructor.indexRoot()},store:function(a){return this.constructor.store(this,a)},retrieve:function(a){return _.defaults(this.attributes,this.constructor.retrieve(this.id,a))},included:function(){return this.concern(f),this.after({initialize:function(){return this.on("sync",this.store),this.retrieve(),this.store()}})}},ClassMethods:{storage:function(){return localStorage},toJSON:function(a){return JSON.stringify(a)},indexRoot:function(){return inflection.transform(this.name,["underscore","pluralize"])},store:function(a,b){var c,d,f,g;if(null!=a&&null!=a.id)return c=null!=(g="function"==typeof this.indexRoot?this.indexRoot():void 0)?g:this.indexRoot,f=""+c+"/"+a.id,null!=b?(f+="/"+e(this.toJSON(b)),d=this.toJSON({instance:a,data:b})):d=this.toJSON(a),this.storage().setItem(f,d),f},retrieve:function(a,b){var c,d,f,g,h,i,j;if(d=null!=(j="function"==typeof this.indexRoot?this.indexRoot():void 0)?j:this.indexRoot,null==a){if(f=this.storage().getItem(e(d)),c=JSON.parse(f),null!=f)for(h=0,i=c.length;i>h;h++)a=c[h],this.retrieve(a);return c}return g=""+d+"/"+a,null!=b&&(g+="/"+b),f=this.storage().getItem(g),null!=f?JSON.parse(f):void 0}},Interactions:function(){return{InstanceMethods:this["with"](d,{included:function(a){return function(){return a.after({initialize:function(){return console.log(this.toJSON(this.name)),this.after({store:function(){return this.log("Stored instances",this.constructor.all().pluck("id"))}})}})}}(this)}),ClassMethods:this["with"](c,{indexRoot:function(){var a;return null!=(a="function"==typeof this.urlRoot?this.urlRoot():void 0)?a:this.urlRoot},extended:function(){return this.after({store:function(){var a,b,c;return b=null!=(c="function"==typeof this.indexRoot?this.indexRoot():void 0)?c:this.indexRoot,a=this.toJSON(this.constructor.all().pluck("id")),this.constructor.storage().setItem(b,a)}})}})}}},b.exports=g}).call(this)},{"../utils/hash":19,"./collectable":10,"./debug":11,"./interceptable":14}],16:[function(a,b){(function(){var c,d,e,f,g={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var d in b)g.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},i=[].slice;d=a("./mixable"),c=a("./mixins/associable"),f=a("./config"),e=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return h(b,a),_.extend(b,d),b.concern(c),b.prototype.syncedAt=0,b.prototype.initialize=function(a,c){var d;return null==a&&(a={}),null==c&&(c={}),this.parent=c.parent||this.parent||(null!=(d=this.collection)?d.parent:void 0),this.synced=c.synced||!1,this.on("change",function(a){return function(){return a.synced=!1}}(this)),this.on("sync",function(a){return function(){return a.synced=!0,a.syncedAt=Date.now()}}(this)),b.__super__.initialize.apply(this,arguments)},b.prototype.urlRoot=function(){return inflection.transform(this.constructor.name||this.constructor.toString().match(/^function\s*([^\s(]+)/)[1],["underscore","pluralize"])},b.prototype.url=function(){var a,b,c,d,e,g,h;return a=(null!=(g=this.parent)&&"function"==typeof g.url?g.url():void 0)||(null!=(h=this.parent)?h.url:void 0)||f.url,d=("function"==typeof this.urlRoot?this.urlRoot():void 0)||this.urlRoot,c=this.id?"/"+this.id:"",b=null!=this.format?"."+(("function"==typeof this.format?this.format():void 0)||this.format):"",e=""+a+"/"+d+c+b},b.prototype.fetch=function(a){var c,d,e,f;if(null==a&&(a={}),!a.force){if(this.syncing)return this._fetchPromise;if(this.synced)return c=Q.defer(),c.resolve(),c.promise}return a.dataType||(a.dataType=this.format),d=b.__super__.fetch.call(this,a),this.synced=!1,this.syncing=!0,c=Q.defer(),f=function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.syncing=!1,c.resolve.apply(c,b)}}(this),e=function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.syncing=!1,c.reject.apply(c,b)}}(this),d.then(function(a){return function(){var b;return b=1<=arguments.length?i.call(arguments,0):[],a.synced?f.apply(null,b):a.once("sync",function(){return f.apply(null,b)})}}(this)),d.fail(function(){return function(){var a;return a=1<=arguments.length?i.call(arguments,0):[],e.apply(null,a)}}(this)),this._fetchPromise=c.promise},b.prototype.save=function(a){return null==a&&(a={}),b.__super__.save.call(this,_.defaults(a,{dataType:this.format}))},b}(Backbone.Deferred.Model),b.exports=e}).call(this)},{"./config":7,"./mixable":8,"./mixins/associable":9}],17:[function(a,b){(function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;a("./utils/rivets-tails"),l=a("./utils/hash"),o=a("./mixable"),n=a("./mixins/interceptable"),h=a("./mixins/debug"),i=a("./mixins/dynamic_attributes"),f=a("./mixins/collectable"),c=a("./mixins/associable"),r=a("./mixins/storage"),m=a("./mixins/history"),g=a("./collection"),d=a("./associations/association"),q=a("./associations/relation"),e=a("./associations/belongs_to_relation"),k=a("./associations/has_one_relation"),j=a("./associations/has_many_relation"),p=a("./model"),t=a("./template"),u=a("./view"),v=a("./config"),s={Mixins:{},Utils:{},Associations:{},Models:{},Views:{}},s.Utils={Hash:l},s.Mixable=o,s.Mixins={Interceptable:n,Collectable:f,Associable:c,Debug:h,DynamicAttributes:i,Storage:r,History:m},s.Collection=g,s.Associations={Relation:q,Association:d,BelongsToRelation:e,HasOneRelation:k,HasManyRelation:j},s.Model=p,s.View=u,s.Template=t,s.config=v,b.exports=s}).call(this)},{"./associations/association":1,"./associations/belongs_to_relation":2,"./associations/has_many_relation":3,"./associations/has_one_relation":4,"./associations/relation":5,"./collection":6,"./config":7,"./mixable":8,"./mixins/associable":9,"./mixins/collectable":10,"./mixins/debug":11,"./mixins/dynamic_attributes":12,"./mixins/history":13,"./mixins/interceptable":14,"./mixins/storage":15,"./model":16,"./template":18,"./utils/hash":19,"./utils/rivets-tails":20,"./view":21}],18:[function(a,b){(function(){var c,d,e,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a +}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};c=a("./mixins/collectable"),d=a("./model"),e=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return g(b,a),b.concern(c),b.prototype.urlRoot="assets",b.prototype.format="html",b.prototype.bind=function(a){return this.fetch({parse:!0}).then(function(b){return function(){var c;return c=$(b.get("html")).clone(),rivets.bind(c,a),c}}(this))},b.prototype.parse=function(a){return{html:a}},b}(d),b.exports=c}).call(this)},{"./mixins/collectable":10,"./model":16}],19:[function(a,b){(function(){var a;a=function(a){var b,c,d,e,f;if(c=0,0===a.length)return c;for(d=e=0,f=a.length;f>=0?f>e:e>f;d=f>=0?++e:--e)b=a.charCodeAt(d),c=(c<<5)-c+b,c&=c;return c},b.exports=a}).call(this)},{}],20:[function(){(function(){"undefined"!=typeof rivets&&null!==rivets&&(rivets.adapters[":"]={subscribe:function(a,b,c){return a instanceof Backbone.Collection&&a.on("add remove reset",c),a.on("change:"+b,c)},unsubscribe:function(a,b,c){return a instanceof Backbone.Collection&&a.off("add remove reset",c),a.off("change:"+b,c)},read:function(a,b){return a instanceof Backbone.Collection?a.models:a.get(b)},publish:function(a,b,c){return a.set(b,c)}})}).call(this)},{}],21:[function(a,b){(function(){var c,d,e,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};c=a("./mixable"),d=a("./template"),e=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return g(b,a),_.extend(b,c),b.prototype.initialize=function(a){return null==a&&(a={}),this.template.constructor===String&&(this.template=d.get(this.template)),this.template.bind(this).then(function(a){return function(b){return a.setElement(b),a.render()}}(this)),b.__super__.initialize.call(this,a)},b.prototype.render=function(){return this.delegateEvents()},b.prototype.setView=function(a){return this.view=a,this.view.render()},b}(Backbone.View),b.exports=e}).call(this)},{"./mixable":8,"./template":18}]},{},[17])(17)}); \ No newline at end of file diff --git a/dist/tails.bundle.js b/dist/tails.bundle.js index c0408cd..8f28faa 100644 --- a/dist/tails.bundle.js +++ b/dist/tails.bundle.js @@ -1,7 +1,3 @@ -// Tails -// version: 0.1.0 -// contributors: Joost Verdoorn,Steffan Sluis -// license: MIT // Underscore.js 1.5.2 // http://underscorejs.org // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors @@ -14298,6 +14294,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { (function() { var root; + root = this; root.Backbone.Deferred = Backbone.Deferred = { @@ -14613,80 +14610,34 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }).call(this); // Rivets.js -// version: 0.8.0 +// version: 0.6.9 // author: Michael Richards // license: MIT (function() { var Rivets, bindMethod, unbindMethod, _ref, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = [].slice, __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Rivets = { - options: ['prefix', 'templateDelimiters', 'rootInterface', 'preloadData', 'handler'], - extensions: ['binders', 'formatters', 'components', 'adapters'], - "public": { - binders: {}, - components: {}, - formatters: {}, - adapters: {}, + binders: {}, + components: {}, + formatters: {}, + adapters: {}, + config: { prefix: 'rv', templateDelimiters: ['{', '}'], rootInterface: '.', preloadData: true, handler: function(context, ev, binding) { return this.call(context, ev, binding.view.models); - }, - configure: function(options) { - var descriptor, key, option, value; - if (options == null) { - options = {}; - } - for (option in options) { - value = options[option]; - if (option === 'binders' || option === 'components' || option === 'formatters' || option === 'adapters') { - for (key in value) { - descriptor = value[key]; - Rivets[option][key] = descriptor; - } - } else { - Rivets["public"][option] = value; - } - } - }, - bind: function(el, models, options) { - var view; - if (models == null) { - models = {}; - } - if (options == null) { - options = {}; - } - view = new Rivets.View(el, models, options); - view.bind(); - return view; - }, - init: function(component, el, data) { - var scope, view; - if (data == null) { - data = {}; - } - if (el == null) { - el = document.createElement('div'); - } - component = Rivets["public"].components[component]; - el.innerHTML = component.template.call(this, el); - scope = component.initialize.call(this, el, data); - view = new Rivets.View(el, scope); - view.bind(); - return view; } } }; - if (window['jQuery'] || window['$']) { + if ('jQuery' in window) { _ref = 'on' in jQuery.prototype ? ['on', 'off'] : ['bind', 'unbind'], bindMethod = _ref[0], unbindMethod = _ref[1]; Rivets.Util = { bindEvent: function(el, event, handler) { @@ -14747,54 +14698,33 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }; } - Rivets.TypeParser = (function() { - function TypeParser() {} - - TypeParser.types = { - primitive: 0, - keypath: 1 - }; + Rivets.KeypathParser = (function() { + function KeypathParser() {} - TypeParser.parse = function(string) { - if (/^'.*'$|^".*"$/.test(string)) { - return { - type: this.types.primitive, - value: string.slice(1, -1) - }; - } else if (string === 'true') { - return { - type: this.types.primitive, - value: true - }; - } else if (string === 'false') { - return { - type: this.types.primitive, - value: false - }; - } else if (string === 'null') { - return { - type: this.types.primitive, - value: null - }; - } else if (string === 'undefined') { - return { - type: this.types.primitive, - value: void 0 - }; - } else if (isNaN(Number(string)) === false) { - return { - type: this.types.primitive, - value: Number(string) - }; - } else { - return { - type: this.types.keypath, - value: string - }; + KeypathParser.parse = function(keypath, interfaces, root) { + var char, current, index, tokens, _i, _ref1; + tokens = []; + current = { + "interface": root, + path: '' + }; + for (index = _i = 0, _ref1 = keypath.length; _i < _ref1; index = _i += 1) { + char = keypath.charAt(index); + if (__indexOf.call(interfaces, char) >= 0) { + tokens.push(current); + current = { + "interface": char, + path: '' + }; + } else { + current.path += char; + } } + tokens.push(current); + return tokens; }; - return TypeParser; + return KeypathParser; })(); @@ -14857,40 +14787,184 @@ if ( typeof window === "object" && typeof window.document === "object" ) { })(); + Rivets.Observer = (function() { + function Observer(view, model, keypath, callback) { + this.view = view; + this.model = model; + this.keypath = keypath; + this.callback = callback; + this.unobserve = __bind(this.unobserve, this); + this.realize = __bind(this.realize, this); + this.value = __bind(this.value, this); + this.publish = __bind(this.publish, this); + this.read = __bind(this.read, this); + this.set = __bind(this.set, this); + this.adapter = __bind(this.adapter, this); + this.update = __bind(this.update, this); + this.initialize = __bind(this.initialize, this); + this.parse = __bind(this.parse, this); + this.parse(); + this.initialize(); + } + + Observer.prototype.parse = function() { + var interfaces, k, path, root, v, _ref1; + interfaces = (function() { + var _ref1, _results; + _ref1 = this.view.adapters; + _results = []; + for (k in _ref1) { + v = _ref1[k]; + if (v) { + _results.push(k); + } + } + return _results; + }).call(this); + if (_ref1 = this.keypath[0], __indexOf.call(interfaces, _ref1) >= 0) { + root = this.keypath[0]; + path = this.keypath.substr(1); + } else { + root = this.view.config.rootInterface; + path = this.keypath; + } + this.tokens = Rivets.KeypathParser.parse(path, interfaces, root); + return this.key = this.tokens.pop(); + }; + + Observer.prototype.initialize = function() { + this.objectPath = []; + this.target = this.realize(); + if (this.target != null) { + return this.set(true, this.key, this.target, this.callback); + } + }; + + Observer.prototype.update = function() { + var next, oldValue; + if ((next = this.realize()) !== this.target) { + if (this.target != null) { + this.set(false, this.key, this.target, this.callback); + } + if (next != null) { + this.set(true, this.key, next, this.callback); + } + oldValue = this.value(); + this.target = next; + if (this.value() !== oldValue) { + return this.callback(); + } + } + }; + + Observer.prototype.adapter = function(key) { + return this.view.adapters[key["interface"]]; + }; + + Observer.prototype.set = function(active, key, obj, callback) { + var action; + action = active ? 'subscribe' : 'unsubscribe'; + return this.adapter(key)[action](obj, key.path, callback); + }; + + Observer.prototype.read = function(key, obj) { + return this.adapter(key).read(obj, key.path); + }; + + Observer.prototype.publish = function(value) { + if (this.target != null) { + return this.adapter(this.key).publish(this.target, this.key.path, value); + } + }; + + Observer.prototype.value = function() { + if (this.target != null) { + return this.read(this.key, this.target); + } + }; + + Observer.prototype.realize = function() { + var current, index, prev, token, unreached, _i, _len, _ref1; + current = this.model; + unreached = null; + _ref1 = this.tokens; + for (index = _i = 0, _len = _ref1.length; _i < _len; index = ++_i) { + token = _ref1[index]; + if (current != null) { + if (this.objectPath[index] != null) { + if (current !== (prev = this.objectPath[index])) { + this.set(false, token, prev, this.update); + this.set(true, token, current, this.update); + this.objectPath[index] = current; + } + } else { + this.set(true, token, current, this.update); + this.objectPath[index] = current; + } + current = this.read(token, current); + } else { + if (unreached == null) { + unreached = index; + } + if (prev = this.objectPath[index]) { + this.set(false, token, prev, this.update); + } + } + } + if (unreached != null) { + this.objectPath.splice(unreached); + } + return current; + }; + + Observer.prototype.unobserve = function() { + var index, obj, token, _i, _len, _ref1; + _ref1 = this.tokens; + for (index = _i = 0, _len = _ref1.length; _i < _len; index = ++_i) { + token = _ref1[index]; + if (obj = this.objectPath[index]) { + this.set(false, token, obj, this.update); + } + } + if (this.target != null) { + return this.set(false, this.key, this.target, this.callback); + } + }; + + return Observer; + + })(); + Rivets.View = (function() { function View(els, models, options) { - var k, option, v, _base, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5; + var k, option, v, _base, _i, _len, _ref1, _ref2, _ref3; this.els = els; this.models = models; - if (options == null) { - options = {}; - } + this.options = options != null ? options : {}; this.update = __bind(this.update, this); this.publish = __bind(this.publish, this); this.sync = __bind(this.sync, this); this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); this.select = __bind(this.select, this); - this.traverse = __bind(this.traverse, this); this.build = __bind(this.build, this); - this.buildBinding = __bind(this.buildBinding, this); + this.componentRegExp = __bind(this.componentRegExp, this); this.bindingRegExp = __bind(this.bindingRegExp, this); - this.options = __bind(this.options, this); if (!(this.els.jquery || this.els instanceof Array)) { this.els = [this.els]; } - _ref1 = Rivets.extensions; + _ref1 = ['config', 'binders', 'formatters', 'adapters']; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { option = _ref1[_i]; this[option] = {}; - if (options[option]) { - _ref2 = options[option]; + if (this.options[option]) { + _ref2 = this.options[option]; for (k in _ref2) { v = _ref2[k]; this[option][k] = v; } } - _ref3 = Rivets["public"][option]; + _ref3 = Rivets[option]; for (k in _ref3) { v = _ref3[k]; if ((_base = this[option])[k] == null) { @@ -14898,100 +14972,130 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } } } - _ref4 = Rivets.options; - for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) { - option = _ref4[_j]; - this[option] = (_ref5 = options[option]) != null ? _ref5 : Rivets["public"][option]; - } this.build(); } - View.prototype.options = function() { - var option, options, _i, _len, _ref1; - options = {}; - _ref1 = Rivets.extensions.concat(Rivets.options); - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - option = _ref1[_i]; - options[option] = this[option]; - } - return options; - }; - View.prototype.bindingRegExp = function() { - return new RegExp("^" + this.prefix + "-"); + return new RegExp("^" + this.config.prefix + "-"); }; - View.prototype.buildBinding = function(binding, node, type, declaration) { - var context, ctx, dependencies, keypath, options, pipe, pipes; - options = {}; - pipes = (function() { - var _i, _len, _ref1, _results; - _ref1 = declaration.split('|'); - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - pipe = _ref1[_i]; - _results.push(pipe.trim()); - } - return _results; - })(); - context = (function() { - var _i, _len, _ref1, _results; - _ref1 = pipes.shift().split('<'); - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - ctx = _ref1[_i]; - _results.push(ctx.trim()); - } - return _results; - })(); - keypath = context.shift(); - options.formatters = pipes; - if (dependencies = context.shift()) { - options.dependencies = dependencies.split(/\s+/); - } - return this.bindings.push(new Rivets[binding](this, node, type, keypath, options)); + View.prototype.componentRegExp = function() { + return new RegExp("^" + (this.config.prefix.toUpperCase()) + "-"); }; View.prototype.build = function() { - var el, parse, _i, _len, _ref1; + var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref1; this.bindings = []; + skipNodes = []; + bindingRegExp = this.bindingRegExp(); + componentRegExp = this.componentRegExp(); + buildBinding = (function(_this) { + return function(binding, node, type, declaration) { + var context, ctx, dependencies, keypath, options, pipe, pipes; + options = {}; + pipes = (function() { + var _i, _len, _ref1, _results; + _ref1 = declaration.split('|'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + pipe = _ref1[_i]; + _results.push(pipe.trim()); + } + return _results; + })(); + context = (function() { + var _i, _len, _ref1, _results; + _ref1 = pipes.shift().split('<'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + ctx = _ref1[_i]; + _results.push(ctx.trim()); + } + return _results; + })(); + keypath = context.shift(); + options.formatters = pipes; + if (dependencies = context.shift()) { + options.dependencies = dependencies.split(/\s+/); + } + return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options)); + }; + })(this); parse = (function(_this) { return function(node) { - var block, childNode, delimiters, n, parser, text, token, tokens, _i, _j, _len, _len1, _ref1, _results; - if (node.nodeType === 3) { - parser = Rivets.TextTemplateParser; - if (delimiters = _this.templateDelimiters) { - if ((tokens = parser.parse(node.data, delimiters)).length) { - if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) { - for (_i = 0, _len = tokens.length; _i < _len; _i++) { - token = tokens[_i]; - text = document.createTextNode(token.value); - node.parentNode.insertBefore(text, node); - if (token.type === 1) { - _this.buildBinding('TextBinding', text, null, token.value); + var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref1, _ref2, _ref3, _ref4, _ref5, _results; + if (__indexOf.call(skipNodes, node) < 0) { + if (node.nodeType === 3) { + parser = Rivets.TextTemplateParser; + if (delimiters = _this.config.templateDelimiters) { + if ((tokens = parser.parse(node.data, delimiters)).length) { + if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) { + for (_i = 0, _len = tokens.length; _i < _len; _i++) { + token = tokens[_i]; + text = document.createTextNode(token.value); + node.parentNode.insertBefore(text, node); + if (token.type === 1) { + buildBinding('TextBinding', text, null, token.value); + } } + node.parentNode.removeChild(node); } - node.parentNode.removeChild(node); + } + } + } else if (componentRegExp.test(node.tagName)) { + type = node.tagName.replace(componentRegExp, '').toLowerCase(); + _this.bindings.push(new Rivets.ComponentBinding(_this, node, type)); + } else if (node.attributes != null) { + _ref1 = node.attributes; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + attribute = _ref1[_j]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + if (!(binder = _this.binders[type])) { + _ref2 = _this.binders; + for (identifier in _ref2) { + value = _ref2[identifier]; + if (identifier !== '*' && identifier.indexOf('*') !== -1) { + regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$"); + if (regexp.test(type)) { + binder = value; + } + } + } + } + binder || (binder = _this.binders['*']); + if (binder.block) { + _ref3 = node.childNodes; + for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { + n = _ref3[_k]; + skipNodes.push(n); + } + attributes = [attribute]; + } + } + } + _ref4 = attributes || node.attributes; + for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) { + attribute = _ref4[_l]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + buildBinding('Binding', node, type, attribute.value); } } } - } else if (node.nodeType === 1) { - block = _this.traverse(node); - } - if (!block) { - _ref1 = (function() { - var _k, _len1, _ref1, _results1; - _ref1 = node.childNodes; + _ref5 = (function() { + var _len4, _n, _ref5, _results1; + _ref5 = node.childNodes; _results1 = []; - for (_k = 0, _len1 = _ref1.length; _k < _len1; _k++) { - n = _ref1[_k]; + for (_n = 0, _len4 = _ref5.length; _n < _len4; _n++) { + n = _ref5[_n]; _results1.push(n); } return _results1; })(); _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - childNode = _ref1[_j]; + for (_m = 0, _len4 = _ref5.length; _m < _len4; _m++) { + childNode = _ref5[_m]; _results.push(parse(childNode)); } return _results; @@ -15003,56 +15107,6 @@ if ( typeof window === "object" && typeof window.document === "object" ) { el = _ref1[_i]; parse(el); } - this.bindings.sort(function(a, b) { - var _ref2, _ref3; - return (((_ref2 = b.binder) != null ? _ref2.priority : void 0) || 0) - (((_ref3 = a.binder) != null ? _ref3.priority : void 0) || 0); - }); - }; - - View.prototype.traverse = function(node) { - var attribute, attributes, binder, bindingRegExp, block, identifier, regexp, type, value, _i, _j, _len, _len1, _ref1, _ref2, _ref3; - bindingRegExp = this.bindingRegExp(); - block = node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE'; - _ref1 = node.attributes; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - attribute = _ref1[_i]; - if (bindingRegExp.test(attribute.name)) { - type = attribute.name.replace(bindingRegExp, ''); - if (!(binder = this.binders[type])) { - _ref2 = this.binders; - for (identifier in _ref2) { - value = _ref2[identifier]; - if (identifier !== '*' && identifier.indexOf('*') !== -1) { - regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); - if (regexp.test(type)) { - binder = value; - } - } - } - } - binder || (binder = this.binders['*']); - if (binder.block) { - block = true; - attributes = [attribute]; - } - } - } - _ref3 = attributes || node.attributes; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - attribute = _ref3[_j]; - if (bindingRegExp.test(attribute.name)) { - type = attribute.name.replace(bindingRegExp, ''); - this.buildBinding('Binding', node, type, attribute.value); - } - } - if (!block) { - type = node.nodeName.toLowerCase(); - if (this.components[type] && !node._bound) { - this.bindings.push(new Rivets.ComponentBinding(this, node, type)); - block = true; - } - } - return block; }; View.prototype.select = function(fn) { @@ -15143,7 +15197,6 @@ if ( typeof window === "object" && typeof window.document === "object" ) { this.type = type; this.keypath = keypath; this.options = options != null ? options : {}; - this.getValue = __bind(this.getValue, this); this.update = __bind(this.update, this); this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); @@ -15152,12 +15205,9 @@ if ( typeof window === "object" && typeof window.document === "object" ) { this.set = __bind(this.set, this); this.eventHandler = __bind(this.eventHandler, this); this.formattedValue = __bind(this.formattedValue, this); - this.parseTarget = __bind(this.parseTarget, this); - this.observe = __bind(this.observe, this); this.setBinder = __bind(this.setBinder, this); this.formatters = this.options.formatters || []; this.dependencies = []; - this.formatterObservers = {}; this.model = void 0; this.setBinder(); } @@ -15169,10 +15219,10 @@ if ( typeof window === "object" && typeof window.document === "object" ) { for (identifier in _ref1) { value = _ref1[identifier]; if (identifier !== '*' && identifier.indexOf('*') !== -1) { - regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); + regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$"); if (regexp.test(this.type)) { this.binder = value; - this.args = new RegExp("^" + (identifier.replace(/\*/g, '(.+)')) + "$").exec(this.type); + this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(this.type); this.args.shift(); } } @@ -15186,50 +15236,18 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Binding.prototype.observe = function(obj, keypath, callback) { - return Rivets.sightglass(obj, keypath, callback, { - root: this.view.rootInterface, - adapters: this.view.adapters - }); - }; - - Binding.prototype.parseTarget = function() { - var token; - token = Rivets.TypeParser.parse(this.keypath); - if (token.type === 0) { - return this.value = token.value; - } else { - this.observer = this.observe(this.view.models, this.keypath, this.sync); - return this.model = this.observer.target; - } - }; - Binding.prototype.formattedValue = function(value) { - var ai, arg, args, fi, formatter, id, observer, processedArgs, _base, _i, _j, _len, _len1, _ref1; + var args, formatter, id, _i, _len, _ref1; _ref1 = this.formatters; - for (fi = _i = 0, _len = _ref1.length; _i < _len; fi = ++_i) { - formatter = _ref1[fi]; - args = formatter.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + formatter = _ref1[_i]; + args = formatter.split(/\s+/); id = args.shift(); formatter = this.view.formatters[id]; - args = (function() { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = args.length; _j < _len1; _j++) { - arg = args[_j]; - _results.push(Rivets.TypeParser.parse(arg)); - } - return _results; - })(); - processedArgs = []; - for (ai = _j = 0, _len1 = args.length; _j < _len1; ai = ++_j) { - arg = args[ai]; - processedArgs.push(arg.type === 0 ? arg.value : ((_base = this.formatterObservers)[fi] || (_base[fi] = {}), !(observer = this.formatterObservers[fi][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[fi][ai] = observer) : void 0, observer.value())); - } if ((formatter != null ? formatter.read : void 0) instanceof Function) { - value = formatter.read.apply(formatter, [value].concat(__slice.call(processedArgs))); + value = formatter.read.apply(formatter, [value].concat(__slice.call(args))); } else if (formatter instanceof Function) { - value = formatter.apply(null, [value].concat(__slice.call(processedArgs))); + value = formatter.apply(null, [value].concat(__slice.call(args))); } } return value; @@ -15237,7 +15255,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { Binding.prototype.eventHandler = function(fn) { var binding, handler; - handler = (binding = this).view.handler; + handler = (binding = this).view.config.handler; return function(ev) { return handler.call(fn, this, ev, binding); }; @@ -15250,109 +15268,86 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }; Binding.prototype.sync = function() { - var dependency, observer; - return this.set((function() { - var _i, _j, _len, _len1, _ref1, _ref2, _ref3; - if (this.observer) { - if (this.model !== this.observer.target) { - _ref1 = this.dependencies; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - observer = _ref1[_i]; - observer.unobserve(); - } - this.dependencies = []; - if (((this.model = this.observer.target) != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { - _ref3 = this.options.dependencies; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - dependency = _ref3[_j]; - observer = this.observe(this.model, dependency, this.sync); - this.dependencies.push(observer); - } - } + var dependency, observer, _i, _j, _len, _len1, _ref1, _ref2, _ref3; + if (this.model !== this.observer.target) { + _ref1 = this.dependencies; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + observer = _ref1[_i]; + observer.unobserve(); + } + this.dependencies = []; + if (((this.model = this.observer.target) != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { + _ref3 = this.options.dependencies; + for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { + dependency = _ref3[_j]; + observer = new Rivets.Observer(this.view, this.model, dependency, this.sync); + this.dependencies.push(observer); } - return this.observer.value(); - } else { - return this.value; } - }).call(this)); + } + return this.set(this.observer.value()); }; Binding.prototype.publish = function() { var args, formatter, id, value, _i, _len, _ref1, _ref2, _ref3; - if (this.observer) { - value = this.getValue(this.el); - _ref1 = this.formatters.slice(0).reverse(); - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - formatter = _ref1[_i]; - args = formatter.split(/\s+/); - id = args.shift(); - if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) { - value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args))); - } + value = Rivets.Util.getInputValue(this.el); + _ref1 = this.formatters.slice(0).reverse(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + formatter = _ref1[_i]; + args = formatter.split(/\s+/); + id = args.shift(); + if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) { + value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args))); } - return this.observer.setValue(value); } + return this.observer.publish(value); }; Binding.prototype.bind = function() { var dependency, observer, _i, _len, _ref1, _ref2, _ref3; - this.parseTarget(); if ((_ref1 = this.binder.bind) != null) { _ref1.call(this, this.el); } + this.observer = new Rivets.Observer(this.view, this.view.models, this.keypath, this.sync); + this.model = this.observer.target; if ((this.model != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { _ref3 = this.options.dependencies; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { dependency = _ref3[_i]; - observer = this.observe(this.model, dependency, this.sync); + observer = new Rivets.Observer(this.view, this.model, dependency, this.sync); this.dependencies.push(observer); } } - if (this.view.preloadData) { + if (this.view.config.preloadData) { return this.sync(); } }; Binding.prototype.unbind = function() { - var ai, args, fi, observer, _i, _len, _ref1, _ref2, _ref3, _ref4; + var observer, _i, _len, _ref1, _ref2; if ((_ref1 = this.binder.unbind) != null) { _ref1.call(this, this.el); } - if ((_ref2 = this.observer) != null) { - _ref2.unobserve(); - } - _ref3 = this.dependencies; - for (_i = 0, _len = _ref3.length; _i < _len; _i++) { - observer = _ref3[_i]; + this.observer.unobserve(); + _ref2 = this.dependencies; + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + observer = _ref2[_i]; observer.unobserve(); } - this.dependencies = []; - _ref4 = this.formatterObservers; - for (fi in _ref4) { - args = _ref4[fi]; - for (ai in args) { - observer = args[ai]; - observer.unobserve(); - } - } - return this.formatterObservers = {}; + return this.dependencies = []; }; Binding.prototype.update = function(models) { - var _ref1, _ref2; + var _ref1; if (models == null) { models = {}; } - this.model = (_ref1 = this.observer) != null ? _ref1.target : void 0; - return (_ref2 = this.binder.update) != null ? _ref2.call(this, models) : void 0; - }; - - Binding.prototype.getValue = function(el) { - if (this.binder && (this.binder.getValue != null)) { - return this.binder.getValue.call(this, el); - } else { - return Rivets.Util.getInputValue(el); + this.model = this.observer.target; + this.unbind(); + if ((_ref1 = this.binder.update) != null) { + _ref1.call(this, models); } + return this.bind(); }; return Binding; @@ -15363,130 +15358,73 @@ if ( typeof window === "object" && typeof window.document === "object" ) { __extends(ComponentBinding, _super); function ComponentBinding(view, el, type) { - var attribute, bindingRegExp, propertyName, _i, _len, _ref1, _ref2; + var attribute, _i, _len, _ref1, _ref2; this.view = view; this.el = el; this.type = type; this.unbind = __bind(this.unbind, this); this.bind = __bind(this.bind, this); + this.update = __bind(this.update, this); this.locals = __bind(this.locals, this); - this.component = this.view.components[this.type]; - this["static"] = {}; - this.observers = {}; - this.upstreamObservers = {}; - bindingRegExp = view.bindingRegExp(); + this.component = Rivets.components[this.type]; + this.attributes = {}; + this.inflections = {}; _ref1 = this.el.attributes || []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { attribute = _ref1[_i]; - if (!bindingRegExp.test(attribute.name)) { - propertyName = this.camelCase(attribute.name); - if (__indexOf.call((_ref2 = this.component["static"]) != null ? _ref2 : [], propertyName) >= 0) { - this["static"][propertyName] = attribute.value; - } else { - this.observers[propertyName] = attribute.value; - } + if (_ref2 = attribute.name, __indexOf.call(this.component.attributes, _ref2) >= 0) { + this.attributes[attribute.name] = attribute.value; + } else { + this.inflections[attribute.name] = attribute.value; } } } ComponentBinding.prototype.sync = function() {}; - ComponentBinding.prototype.locals = function() { - var key, observer, result, value, _ref1, _ref2; + ComponentBinding.prototype.locals = function(models) { + var inverse, key, model, path, result, _i, _len, _ref1, _ref2; + if (models == null) { + models = this.view.models; + } result = {}; - _ref1 = this["static"]; + _ref1 = this.inflections; for (key in _ref1) { - value = _ref1[key]; - result[key] = value; + inverse = _ref1[key]; + _ref2 = inverse.split('.'); + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + path = _ref2[_i]; + result[key] = (result[key] || models)[path]; + } } - _ref2 = this.observers; - for (key in _ref2) { - observer = _ref2[key]; - result[key] = observer.value(); + for (key in models) { + model = models[key]; + if (result[key] == null) { + result[key] = model; + } } return result; }; - ComponentBinding.prototype.camelCase = function(string) { - return string.replace(/-([a-z])/g, function(grouped) { - return grouped[1].toUpperCase(); - }); + ComponentBinding.prototype.update = function(models) { + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.update(this.locals(models)) : void 0; }; ComponentBinding.prototype.bind = function() { - var k, key, keypath, observer, option, options, scope, v, _base, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _results; - if (!this.bound) { - _ref1 = this.observers; - for (key in _ref1) { - keypath = _ref1[key]; - this.observers[key] = this.observe(this.view.models, keypath, (function(_this) { - return function() { - return _this.componentView.models[key] = _this.observers[key].value(); - }; - })(this)); - } - this.bound = true; - } + var el, _ref1; if (this.componentView != null) { - return this.componentView.bind(); + return (_ref1 = this.componentView) != null ? _ref1.bind() : void 0; } else { - this.el.innerHTML = this.component.template.call(this); - scope = this.component.initialize.call(this, this.el, this.locals()); - this.el._bound = true; - options = {}; - _ref2 = Rivets.extensions; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - option = _ref2[_i]; - options[option] = {}; - if (this.component[option]) { - _ref3 = this.component[option]; - for (k in _ref3) { - v = _ref3[k]; - options[option][k] = v; - } - } - _ref4 = this.view[option]; - for (k in _ref4) { - v = _ref4[k]; - if ((_base = options[option])[k] == null) { - _base[k] = v; - } - } - } - _ref5 = Rivets.options; - for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) { - option = _ref5[_j]; - options[option] = (_ref6 = this.component[option]) != null ? _ref6 : this.view[option]; - } - this.componentView = new Rivets.View(this.el, scope, options); - this.componentView.bind(); - _ref7 = this.observers; - _results = []; - for (key in _ref7) { - observer = _ref7[key]; - _results.push(this.upstreamObservers[key] = this.observe(this.componentView.models, key, (function(_this) { - return function() { - return observer.setValue(_this.componentView.models[key]); - }; - })(this))); - } - return _results; + el = this.component.build.call(this.attributes); + (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind(); + return this.el.parentNode.replaceChild(el, this.el); } }; ComponentBinding.prototype.unbind = function() { - var key, observer, _ref1, _ref2, _ref3; - _ref1 = this.upstreamObservers; - for (key in _ref1) { - observer = _ref1[key]; - observer.unobserve(); - } - _ref2 = this.observers; - for (key in _ref2) { - observer = _ref2[key]; - observer.unobserve(); - } - return (_ref3 = this.componentView) != null ? _ref3.unbind.call(this) : void 0; + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.unbind() : void 0; }; return ComponentBinding; @@ -15505,7 +15443,6 @@ if ( typeof window === "object" && typeof window.document === "object" ) { this.sync = __bind(this.sync, this); this.formatters = this.options.formatters || []; this.dependencies = []; - this.formatterObservers = {}; } TextBinding.prototype.binder = { @@ -15522,44 +15459,162 @@ if ( typeof window === "object" && typeof window.document === "object" ) { })(Rivets.Binding); - Rivets["public"].binders.text = function(el, value) { - if (el.textContent != null) { - return el.textContent = value != null ? value : ''; - } else { - return el.innerText = value != null ? value : ''; - } - }; - - Rivets["public"].binders.html = function(el, value) { - return el.innerHTML = value != null ? value : ''; - }; - - Rivets["public"].binders.show = function(el, value) { - return el.style.display = value ? '' : 'none'; - }; - - Rivets["public"].binders.hide = function(el, value) { - return el.style.display = value ? 'none' : ''; - }; - - Rivets["public"].binders.enabled = function(el, value) { - return el.disabled = !value; - }; - - Rivets["public"].binders.disabled = function(el, value) { - return el.disabled = !!value; - }; - - Rivets["public"].binders.checked = { - publishes: true, - priority: 2000, - bind: function(el) { - return Rivets.Util.bindEvent(el, 'change', this.publish); - }, - unbind: function(el) { - return Rivets.Util.unbindEvent(el, 'change', this.publish); - }, - routine: function(el, value) { + Rivets.adapters['.'] = { + id: '_rv', + counter: 0, + weakmap: {}, + weakReference: function(obj) { + var id; + if (!obj.hasOwnProperty(this.id)) { + id = this.counter++; + this.weakmap[id] = { + callbacks: {} + }; + Object.defineProperty(obj, this.id, { + value: id + }); + } + return this.weakmap[obj[this.id]]; + }, + stubFunction: function(obj, fn) { + var map, original, weakmap; + original = obj[fn]; + map = this.weakReference(obj); + weakmap = this.weakmap; + return obj[fn] = function() { + var callback, k, r, response, _i, _len, _ref1, _ref2, _ref3, _ref4; + response = original.apply(obj, arguments); + _ref1 = map.pointers; + for (r in _ref1) { + k = _ref1[r]; + _ref4 = (_ref2 = (_ref3 = weakmap[r]) != null ? _ref3.callbacks[k] : void 0) != null ? _ref2 : []; + for (_i = 0, _len = _ref4.length; _i < _len; _i++) { + callback = _ref4[_i]; + callback(); + } + } + return response; + }; + }, + observeMutations: function(obj, ref, keypath) { + var fn, functions, map, _base, _i, _len; + if (Array.isArray(obj)) { + map = this.weakReference(obj); + if (map.pointers == null) { + map.pointers = {}; + functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice']; + for (_i = 0, _len = functions.length; _i < _len; _i++) { + fn = functions[_i]; + this.stubFunction(obj, fn); + } + } + if ((_base = map.pointers)[ref] == null) { + _base[ref] = []; + } + if (__indexOf.call(map.pointers[ref], keypath) < 0) { + return map.pointers[ref].push(keypath); + } + } + }, + unobserveMutations: function(obj, ref, keypath) { + var idx, keypaths, _ref1; + if (Array.isArray(obj && (obj[this.id] != null))) { + if (keypaths = (_ref1 = this.weakReference(obj).pointers) != null ? _ref1[ref] : void 0) { + idx = keypaths.indexOf(keypath); + if (idx >= 0) { + return keypaths.splice(idx, 1); + } + } + } + }, + subscribe: function(obj, keypath, callback) { + var callbacks, value; + callbacks = this.weakReference(obj).callbacks; + if (callbacks[keypath] == null) { + callbacks[keypath] = []; + value = obj[keypath]; + Object.defineProperty(obj, keypath, { + enumerable: true, + get: function() { + return value; + }, + set: (function(_this) { + return function(newValue) { + var _i, _len, _ref1; + if (newValue !== value) { + value = newValue; + _ref1 = callbacks[keypath].slice(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + callback = _ref1[_i]; + if (__indexOf.call(callbacks[keypath], callback) >= 0) { + callback(); + } + } + return _this.observeMutations(newValue, obj[_this.id], keypath); + } + }; + })(this) + }); + } + if (__indexOf.call(callbacks[keypath], callback) < 0) { + callbacks[keypath].push(callback); + } + return this.observeMutations(obj[keypath], obj[this.id], keypath); + }, + unsubscribe: function(obj, keypath, callback) { + var callbacks, idx; + callbacks = this.weakmap[obj[this.id]].callbacks[keypath]; + idx = callbacks.indexOf(callback); + if (idx >= 0) { + callbacks.splice(idx, 1); + } + return this.unobserveMutations(obj[keypath], obj[this.id], keypath); + }, + read: function(obj, keypath) { + return obj[keypath]; + }, + publish: function(obj, keypath, value) { + return obj[keypath] = value; + } + }; + + Rivets.binders.text = function(el, value) { + if (el.textContent != null) { + return el.textContent = value != null ? value : ''; + } else { + return el.innerText = value != null ? value : ''; + } + }; + + Rivets.binders.html = function(el, value) { + return el.innerHTML = value != null ? value : ''; + }; + + Rivets.binders.show = function(el, value) { + return el.style.display = value ? '' : 'none'; + }; + + Rivets.binders.hide = function(el, value) { + return el.style.display = value ? 'none' : ''; + }; + + Rivets.binders.enabled = function(el, value) { + return el.disabled = !value; + }; + + Rivets.binders.disabled = function(el, value) { + return el.disabled = !!value; + }; + + Rivets.binders.checked = { + publishes: true, + bind: function(el) { + return Rivets.Util.bindEvent(el, 'change', this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, 'change', this.publish); + }, + routine: function(el, value) { var _ref1; if (el.type === 'radio') { return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) === (value != null ? value.toString() : void 0); @@ -15569,9 +15624,8 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders.unchecked = { + Rivets.binders.unchecked = { publishes: true, - priority: 2000, bind: function(el) { return Rivets.Util.bindEvent(el, 'change', this.publish); }, @@ -15588,25 +15642,17 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders.value = { + Rivets.binders.value = { publishes: true, - priority: 3000, bind: function(el) { - if (!(el.tagName === 'INPUT' && el.type === 'radio')) { - this.event = el.tagName === 'SELECT' ? 'change' : 'input'; - return Rivets.Util.bindEvent(el, this.event, this.publish); - } + return Rivets.Util.bindEvent(el, 'change', this.publish); }, unbind: function(el) { - if (!(el.tagName === 'INPUT' && el.type === 'radio')) { - return Rivets.Util.unbindEvent(el, this.event, this.publish); - } + return Rivets.Util.unbindEvent(el, 'change', this.publish); }, routine: function(el, value) { var o, _i, _len, _ref1, _ref2, _ref3, _results; - if (el.tagName === 'INPUT' && el.type === 'radio') { - return el.setAttribute('value', value); - } else if (window.jQuery != null) { + if (window.jQuery != null) { el = jQuery(el); if ((value != null ? value.toString() : void 0) !== ((_ref1 = el.val()) != null ? _ref1.toString() : void 0)) { return el.val(value != null ? value : ''); @@ -15628,16 +15674,14 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders["if"] = { + Rivets.binders["if"] = { block: true, - priority: 4000, bind: function(el) { var attr, declaration; if (this.marker == null) { - attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + attr = [this.view.config.prefix, this.type].join('-').replace('--', '-'); declaration = el.getAttribute(attr); this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " "); - this.bound = false; el.removeAttribute(attr); el.parentNode.insertBefore(this.marker, el); return el.parentNode.removeChild(el); @@ -15648,8 +15692,8 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return (_ref1 = this.nested) != null ? _ref1.unbind() : void 0; }, routine: function(el, value) { - var key, model, models, _ref1; - if (!!value === !this.bound) { + var key, model, models, options, _ref1; + if (!!value === (this.nested == null)) { if (value) { models = {}; _ref1 = this.view.models; @@ -15657,13 +15701,18 @@ if ( typeof window === "object" && typeof window.document === "object" ) { model = _ref1[key]; models[key] = model; } - (this.nested || (this.nested = new Rivets.View(el, models, this.view.options()))).bind(); - this.marker.parentNode.insertBefore(el, this.marker.nextSibling); - return this.bound = true; + options = { + binders: this.view.options.binders, + formatters: this.view.options.formatters, + adapters: this.view.options.adapters, + config: this.view.options.config + }; + (this.nested = new Rivets.View(el, models, options)).bind(); + return this.marker.parentNode.insertBefore(el, this.marker.nextSibling); } else { el.parentNode.removeChild(el); this.nested.unbind(); - return this.bound = false; + return delete this.nested; } } }, @@ -15673,26 +15722,24 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders.unless = { + Rivets.binders.unless = { block: true, - priority: 4000, bind: function(el) { - return Rivets["public"].binders["if"].bind.call(this, el); + return Rivets.binders["if"].bind.call(this, el); }, unbind: function() { - return Rivets["public"].binders["if"].unbind.call(this); + return Rivets.binders["if"].unbind.call(this); }, routine: function(el, value) { - return Rivets["public"].binders["if"].routine.call(this, el, !value); + return Rivets.binders["if"].routine.call(this, el, !value); }, update: function(models) { - return Rivets["public"].binders["if"].update.call(this, models); + return Rivets.binders["if"].update.call(this, models); } }; - Rivets["public"].binders['on-*'] = { + Rivets.binders['on-*'] = { "function": true, - priority: 1000, unbind: function(el) { if (this.handler) { return Rivets.Util.unbindEvent(el, this.args[0], this.handler); @@ -15706,13 +15753,12 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders['each-*'] = { + Rivets.binders['each-*'] = { block: true, - priority: 4000, bind: function(el) { var attr, view, _i, _len, _ref1; if (this.marker == null) { - attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + attr = [this.view.config.prefix, this.type].join('-').replace('--', '-'); this.marker = document.createComment(" rivets: " + this.type + " "); this.iterated = []; el.removeAttribute(attr); @@ -15739,7 +15785,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }, routine: function(el, collection) { - var binding, data, i, index, key, model, modelName, options, previous, template, view, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results; + var binding, data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _ref4, _results; modelName = this.args[0]; collection = collection || []; if (this.iterated.length > collection.length) { @@ -15766,8 +15812,18 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } } previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; - options = this.view.options(); - options.preloadData = true; + options = { + binders: this.view.options.binders, + formatters: this.view.options.formatters, + adapters: this.view.options.adapters, + config: {} + }; + _ref3 = this.view.options.config; + for (k in _ref3) { + v = _ref3[k]; + options.config[k] = v; + } + options.config.preloadData = true; template = el.cloneNode(true); view = new Rivets.View(template, data, options); view.bind(); @@ -15778,10 +15834,10 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } } if (el.nodeName === 'OPTION') { - _ref3 = this.view.bindings; + _ref4 = this.view.bindings; _results = []; - for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { - binding = _ref3[_k]; + for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { + binding = _ref4[_k]; if (binding.el === this.marker.parentNode && binding.type === 'value') { _results.push(binding.sync()); } else { @@ -15810,7 +15866,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders['class-*'] = function(el, value) { + Rivets.binders['class-*'] = function(el, value) { var elClass; elClass = " " + el.className + " "; if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) { @@ -15818,7 +15874,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].binders['*'] = function(el, value) { + Rivets.binders['*'] = function(el, value) { if (value != null) { return el.setAttribute(this.type, value); } else { @@ -15826,762 +15882,448 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Rivets["public"].adapters['.'] = { - id: '_rv', - counter: 0, - weakmap: {}, - weakReference: function(obj) { - var id, _base, _name; - if (!obj.hasOwnProperty(this.id)) { - id = this.counter++; - Object.defineProperty(obj, this.id, { - value: id - }); - } - return (_base = this.weakmap)[_name = obj[this.id]] || (_base[_name] = { - callbacks: {} - }); - }, - cleanupWeakReference: function(ref, id) { - if (!Object.keys(ref.callbacks).length) { - if (!(ref.pointers && Object.keys(ref.pointers).length)) { - return delete this.weakmap[id]; - } - } - }, - stubFunction: function(obj, fn) { - var map, original, weakmap; - original = obj[fn]; - map = this.weakReference(obj); - weakmap = this.weakmap; - return obj[fn] = function() { - var callback, k, r, response, _i, _len, _ref1, _ref2, _ref3, _ref4; - response = original.apply(obj, arguments); - _ref1 = map.pointers; - for (r in _ref1) { - k = _ref1[r]; - _ref4 = (_ref2 = (_ref3 = weakmap[r]) != null ? _ref3.callbacks[k] : void 0) != null ? _ref2 : []; - for (_i = 0, _len = _ref4.length; _i < _len; _i++) { - callback = _ref4[_i]; - callback(); - } - } - return response; - }; - }, - observeMutations: function(obj, ref, keypath) { - var fn, functions, map, _base, _i, _len; - if (Array.isArray(obj)) { - map = this.weakReference(obj); - if (map.pointers == null) { - map.pointers = {}; - functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice']; - for (_i = 0, _len = functions.length; _i < _len; _i++) { - fn = functions[_i]; - this.stubFunction(obj, fn); - } - } - if ((_base = map.pointers)[ref] == null) { - _base[ref] = []; - } - if (__indexOf.call(map.pointers[ref], keypath) < 0) { - return map.pointers[ref].push(keypath); - } - } - }, - unobserveMutations: function(obj, ref, keypath) { - var idx, map, pointers; - if (Array.isArray(obj) && (obj[this.id] != null)) { - if (map = this.weakmap[obj[this.id]]) { - if (pointers = map.pointers[ref]) { - if ((idx = pointers.indexOf(keypath)) >= 0) { - pointers.splice(idx, 1); - } - if (!pointers.length) { - delete map.pointers[ref]; - } - return this.cleanupWeakReference(map, obj[this.id]); - } - } + Rivets.factory = function(exports) { + exports._ = Rivets; + exports.binders = Rivets.binders; + exports.components = Rivets.components; + exports.formatters = Rivets.formatters; + exports.adapters = Rivets.adapters; + exports.config = Rivets.config; + exports.configure = function(options) { + var property, value; + if (options == null) { + options = {}; } - }, - observe: function(obj, keypath, callback) { - var callbacks, desc, value; - callbacks = this.weakReference(obj).callbacks; - if (callbacks[keypath] == null) { - callbacks[keypath] = []; - desc = Object.getOwnPropertyDescriptor(obj, keypath); - if (!((desc != null ? desc.get : void 0) || (desc != null ? desc.set : void 0))) { - value = obj[keypath]; - Object.defineProperty(obj, keypath, { - enumerable: true, - get: function() { - return value; - }, - set: (function(_this) { - return function(newValue) { - var map, _i, _len, _ref1; - if (newValue !== value) { - _this.unobserveMutations(value, obj[_this.id], keypath); - value = newValue; - if (map = _this.weakmap[obj[_this.id]]) { - callbacks = map.callbacks; - if (callbacks[keypath]) { - _ref1 = callbacks[keypath].slice(); - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - callback = _ref1[_i]; - if (__indexOf.call(callbacks[keypath], callback) >= 0) { - callback(); - } - } - } - return _this.observeMutations(newValue, obj[_this.id], keypath); - } - } - }; - })(this) - }); - } + for (property in options) { + value = options[property]; + Rivets.config[property] = value; } - if (__indexOf.call(callbacks[keypath], callback) < 0) { - callbacks[keypath].push(callback); + }; + return exports.bind = function(el, models, options) { + var view; + if (models == null) { + models = {}; } - return this.observeMutations(obj[keypath], obj[this.id], keypath); - }, - unobserve: function(obj, keypath, callback) { - var callbacks, idx, map; - if (map = this.weakmap[obj[this.id]]) { - if (callbacks = map.callbacks[keypath]) { - if ((idx = callbacks.indexOf(callback)) >= 0) { - callbacks.splice(idx, 1); - if (!callbacks.length) { - delete map.callbacks[keypath]; - } - } - this.unobserveMutations(obj[keypath], obj[this.id], keypath); - return this.cleanupWeakReference(map, obj[this.id]); - } + if (options == null) { + options = {}; } - }, - get: function(obj, keypath) { - return obj[keypath]; - }, - set: function(obj, keypath, value) { - return obj[keypath] = value; - } - }; - - Rivets.factory = function(sightglass) { - Rivets.sightglass = sightglass; - Rivets["public"]._ = Rivets; - return Rivets["public"]; + view = new Rivets.View(el, models, options); + view.bind(); + return view; + }; }; - if (typeof (typeof module !== "undefined" && module !== null ? module.exports : void 0) === 'object') { - module.exports = Rivets.factory(require('sightglass')); + if (typeof exports === 'object') { + Rivets.factory(exports); } else if (typeof define === 'function' && define.amd) { - define(['sightglass'], function(sightglass) { - return this.rivets = Rivets.factory(sightglass); + define(['exports'], function(exports) { + Rivets.factory(this.rivets = exports); + return exports; }); } else { - this.rivets = Rivets.factory(sightglass); + Rivets.factory(this.rivets = {}); } }).call(this); +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Tails = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o _ref; i = 0 <= _ref ? ++_i : --_i) { - char = string.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; + Collectable = require('../mixins/collectable'); + + Debug = require('../mixins/debug'); + + DynamicAttributes = require('../mixins/dynamic_attributes'); + + Association = (function(_super) { + __extends(Association, _super); + + function Association() { + return Association.__super__.constructor.apply(this, arguments); } - return hash; - }; - Tails.Mixins.Interceptable = { - InstanceMethods: { - before: function(interceptors) { - return this.intercept({ - before: interceptors - }); - }, - after: function(interceptors) { - return this.intercept({ - after: interceptors - }); - }, - intercept: function(params) { - var fn, fns, interceptors, k, key, klass, placement, v, _i, _len, _ref, _results; - klass = this.constructor; - _results = []; - for (placement in params) { - interceptors = params[placement]; - if (!(placement === 'before' || placement === 'after')) { - continue; - } - if (interceptors.these != null) { - _ref = interceptors.these; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - key = _ref[_i]; - if (typeof key === 'function') { - for (k in this) { - v = this[k]; - if (key === v) { - key = k; - break; - } - } - } - interceptors[key] = interceptors["do"]; - } - } - interceptors = _(interceptors).omit('these', 'do'); - _results.push((function() { - var _results1; - _results1 = []; - for (key in interceptors) { - fns = interceptors[key]; - if (!_(fns).isArray()) { - fns = [fns]; - } - _results1.push((function() { - var _j, _len1, _results2; - _results2 = []; - for (_j = 0, _len1 = fns.length; _j < _len1; _j++) { - fn = fns[_j]; - _results2.push((function(_this) { - return function(key, fn) { - var after, before, interceptable, prev, _ref1, _ref2, _ref3, _ref4; - if ((_this.hasOwnProperty(key) || klass.prototype.hasOwnProperty(key)) && !((_this[key].before != null) || (_this[key].after != null))) { - interceptable = _this[key]; - return _this[key] = function() { - var args, ret; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (placement === 'before') { - (this[fn] || fn).apply(this, args); - } - ret = interceptable.apply(this, args); - if (placement === 'after') { - (this[fn] || fn).apply(this, args); - } - return ret; - }; - } else { - before = ((_ref1 = _this[key]) != null ? _ref1.klass : void 0) === klass ? (_ref2 = _this[key]) != null ? _ref2.before : void 0 : void 0; - after = ((_ref3 = _this[key]) != null ? _ref3.klass : void 0) === klass ? (_ref4 = _this[key]) != null ? _ref4.after : void 0 : void 0; - if (placement === 'before') { - prev = before; - before = function() { - var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (prev != null) { - prev.apply(this, args); - } - return (this[fn] || fn).apply(this, args); - }; - } else if (placement === 'after') { - prev = after; - after = function() { - var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - (this[fn] || fn).apply(this, args); - return prev != null ? prev.apply(this, args) : void 0; - }; - } - return Object.defineProperty(_this, key, { - configurable: true, - set: function(interceptable) { - return Object.defineProperty(this, key, { - writable: true, - value: function() { - var args, ret; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (before != null) { - before.apply(this, args); - } - ret = interceptable.apply(this, args); - if (after != null) { - after.apply(this, args); - } - return ret; - } - }); - }, - get: function() { - var interceptor; - interceptor = function() { - var args, ret, superFn, _ref5; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (before != null) { - before.apply(this, args); - } - superFn = (_ref5 = this.constructor.__super__) != null ? _ref5[key] : void 0; - if ((superFn != null ? superFn.klass : void 0) !== klass) { - ret = superFn != null ? superFn.apply(this, args) : void 0; - } - if (after != null) { - after.apply(this, args); - } - return ret; - }; - interceptor.before = before; - interceptor.after = after; - interceptor.klass = klass; - return interceptor; - } - }); - } - }; - })(this)(key, fn)); - } - return _results2; - }).call(this)); - } - return _results1; - }).call(this)); - } - return _results; - } - }, - ClassMethods: { - before: function(interceptors) { - if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { - return this.before({ - initialize: function() { - return this.before(interceptors.call(this)); - } - }); - } else { - return this.prototype.before(interceptors); - } - }, - after: function(interceptors) { - if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { - return this.before({ - initialize: function() { - return this.after(interceptors.call(this)); - } - }); - } else { - return this.prototype.after(interceptors); - } - } - } - }; + _.extend(Association, Mixable); - Tails.Mixins.Debug = { - InstanceMethods: { - LOG_LEVELS: { - "ERROR": true, - "WARNING": true, - "INFO": false - }, - _excludedMethods: _.union(Object.keys(Tails.Mixins.Interceptable.InstanceMethods), ["constructor", "log", "message", "warn", "error", "info"]), - debug: function() { - return this.LOG_LEVELS.INFO = true; - }, - message: function() { - var line, thing, things, _i, _len; - things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - line = "" + (new Date()) + " - "; - for (_i = 0, _len = things.length; _i < _len; _i++) { - thing = things[_i]; - if (thing.constructor.name === "String") { - line += thing + " "; - } else { - line += JSON.stringify(thing) + " "; - } - } - line += "in " + this.constructor.name + "(" + this.id + ")"; - return line; - }, - error: function() { - var line, things; - things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (!this.LOG_LEVELS.ERROR) { - return; - } - line = this.message.apply(this, things); - return console.error(line); - }, - warn: function() { - var line, things; - things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (!this.LOG_LEVELS.WARNING) { - return; - } - line = this.message.apply(this, things); - return console.warn(line); - }, - log: function() { - var line, things; - things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - line = this.message.apply(this, things); - return console.log(line); - }, - info: function() { - var line, things; - things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (!this.LOG_LEVELS.INFO) { - return; - } - line = this.message.apply(this, things); - return console.log(line); - }, - included: function() { - this.concern(Tails.Mixins.Interceptable); - return this.after({ - initialize: function() { - var args, funcs, key, value, _i, _len, _results; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - this.info("Called function 'initialize' of " + this.constructor.name + " with arguments:", args); - this.on("change", (function(_this) { - return function(event) { - return _this.info("Change of attributes:", event.changedAttributes()); - }; - })(this)); - funcs = (function() { - var _results; - _results = []; - for (key in this) { - value = this[key]; - if (value instanceof Function && __indexOf.call(this._excludedMethods, key) < 0) { - _results.push(key); - } else { - continue; - } - } - return _results; - }).call(this); - _results = []; - for (_i = 0, _len = funcs.length; _i < _len; _i++) { - key = funcs[_i]; - _results.push((function(_this) { - return function(key) { - return _this.after({ - "these": [key], - "do": function() { - var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - return this.info("Called function '" + key + "' of " + this.constructor.name + " with arguments:", args); - } - }); - }; - })(this)(key)); - } - return _results; - } + Association.concern(Debug); + + Association.concern(DynamicAttributes); + + Association.concern(Collectable); + + Association.prototype.relations = function() { + var Collection, Relation; + Collection = require('../collection'); + Relation = require('./relation'); + if (this._relations == null) { + this._relations = new Collection([], { + model: Relation }); } - } - }; + return this._relations; + }; - Tails.Mixable = { - MixableKeywords: ['included', 'extended', 'constructor', 'Interactions', 'InstanceMethods', 'ClassMethods'], - _include: function(mixin) { - var funcs, key, value, _ref; - if (mixin.InstanceMethods != null) { - funcs = mixin.InstanceMethods; - } else if (mixin.ClassMethods != null) { - return; - } else { - funcs = mixin; - } - for (key in funcs) { - value = funcs[key]; - if (__indexOf.call(Tails.Mixable.MixableKeywords, key) < 0) { - if (value != null) { - this.prototype[key] = value; - } - } - } - return (_ref = funcs.included) != null ? _ref.apply(this) : void 0; - }, - _extend: function(mixin) { - var funcs, key, value, _ref; - if (mixin.ClassMethods != null) { - funcs = mixin.ClassMethods; - } else if (mixin.InstanceMethods != null) { - return; - } else { - funcs = mixin; - } - for (key in funcs) { - value = funcs[key]; - if (__indexOf.call(Tails.Mixable.MixableKeywords, key) < 0) { - if (value != null) { - this[key] = value; + Association.prototype.apply = function(owner) { + var BelongsToRelation, HasManyRelation, HasOneRelation, attrs, model, models, relation; + BelongsToRelation = require('./belongs_to_relation'); + HasOneRelation = require('./has_one_relation'); + HasManyRelation = require('./has_many_relation'); + attrs = { + association: this, + from: this.get('from'), + to: this.get('to'), + name: this.get('name'), + owner: owner + }; + switch (this.get('type')) { + case 'belongsTo': + model = owner.get(attrs.name); + relation = new BelongsToRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.to.name || attrs.to.toString().match(/^function\s*([^\s(]+)/)[1]) + })); + if (model != null) { + relation.set("target", model); } - } - } - return (_ref = funcs.extended) != null ? _ref.apply(this) : void 0; - }, - include: function() { - var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; - mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (((_ref = this._includedMixins) != null ? _ref.klass : void 0) !== this) { - this._includedMixins = _(this._includedMixins).clone() || []; - this._includedMixins.klass = this; - } - for (_i = 0, _len = mixins.length; _i < _len; _i++) { - mixin = mixins[_i]; - if (__indexOf.call(this._includedMixins, mixin) >= 0) { - continue; - } - if (mixin != null) { - this._includedMixins.push(mixin); - } - this._include(mixin); - if (mixin.Interactions != null) { - interactions = mixin.Interactions.apply(this); - if (interactions != null) { - this._include(interactions); + break; + case 'hasOne': + model = owner.get(attrs.name); + relation = new HasOneRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), + through: this.get('through'), + source: this.get('source') || this.get('name') + })); + if (model != null) { + relation.set("target", model); } - } - } - _ref1 = this._includedMixins; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - mixin = _ref1[_j]; - if (mixin.Interactions != null) { - interactions = mixin.Interactions.apply(this); - if (interactions != null) { - this._include(interactions); + break; + case 'hasMany': + models = owner.get(attrs.name); + relation = new HasManyRelation(_.extend(attrs, { + foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), + through: this.get('through'), + source: this.get('source') || this.get('name') + })); + if (models != null) { + relation.set("target", models); } - } - } - return this; - }, - extend: function() { - var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; - mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (((_ref = this._extendedMixins) != null ? _ref.klass : void 0) !== this) { - this._extendedMixins = _(this._extendedMixins).clone() || []; - this._extendedMixins.klass = this; } - for (_i = 0, _len = mixins.length; _i < _len; _i++) { - mixin = mixins[_i]; - if (__indexOf.call(this._extendedMixins, mixin) >= 0) { - continue; - } - if (mixin != null) { - this._extendedMixins.push(mixin); + this.relations().add(relation); + owner.relations().add(relation); + owner.getter(attrs.name, function() { + return relation.get('target'); + }); + return owner.setter(attrs.name, function(value) { + return relation.set('target', value); + }); + }; + + return Association; + + })(Backbone.Model); + + module.exports = Association; + +}).call(this); + +//# sourceMappingURL=association.js.map + +},{"../collection":6,"../mixable":8,"../mixins/collectable":10,"../mixins/debug":11,"../mixins/dynamic_attributes":12,"./belongs_to_relation":2,"./has_many_relation":3,"./has_one_relation":4,"./relation":5}],2:[function(require,module,exports){ +(function() { + var BelongsToRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + BelongsToRelation = (function(_super) { + __extends(BelongsToRelation, _super); + + function BelongsToRelation() { + return BelongsToRelation.__super__.constructor.apply(this, arguments); + } + + BelongsToRelation.prototype.initialize = function() { + var association, foreignKey, owner, to; + association = this.get('association'); + to = association.get('to'); + foreignKey = this.get('foreignKey'); + owner = this.get('owner'); + this.getter({ + target: function() { + return to.get(owner.get(foreignKey)); } - this._extend(mixin); - if (mixin.Interactions != null) { - interactions = mixin.Interactions.apply(this); - if (interactions != null) { - this._extend(interactions); + }); + this.setter({ + target: function(model) { + if (model == null) { + this.set(foreignKey, null); + return; } - } - } - _ref1 = this._extendedMixins; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - mixin = _ref1[_j]; - if (mixin.Interactions != null) { - interactions = mixin.Interactions.apply(this); - if (interactions != null) { - this._extend(interactions); + if (to.all().get(model.id) == null) { + to.all().add(model, { + parse: true + }); } + return owner.set(foreignKey, model.id); } - } - return this; - }, - "with": function(mixin, funcs) { - if (funcs == null) { - funcs = {}; - } - if (__indexOf.call(this._includedMixins, mixin) >= 0 || __indexOf.call(this._extendedMixins, mixin) >= 0) { - return funcs; - } else { - return null; - } - }, - concern: function() { - var mixin, mixins, _i, _len; - mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - for (_i = 0, _len = mixins.length; _i < _len; _i++) { - mixin = mixins[_i]; - this.include(mixin); - this.extend(mixin); - } - return this; + }); + return BelongsToRelation.__super__.initialize.apply(this, arguments); + }; + + return BelongsToRelation; + + })(Relation); + + module.exports = BelongsToRelation; + +}).call(this); + +//# sourceMappingURL=belongs_to_relation.js.map + +},{"./relation":5}],3:[function(require,module,exports){ +(function() { + var Collection, HasManyRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + Collection = require('../collection'); + + HasManyRelation = (function(_super) { + __extends(HasManyRelation, _super); + + function HasManyRelation() { + return HasManyRelation.__super__.constructor.apply(this, arguments); } - }; - Tails.Mixins.DynamicAttributes = { - InstanceMethods: { - getter: function(getters, fn) { - var name; - if (fn == null) { - fn = null; - } - if (typeof getters === 'string' && (fn != null)) { - name = getters; - (getters = {})[name] = fn; - } - return this.defineAttribute({ - getter: getters - }); - }, - setter: function(setters, fn) { - var name; - if (fn == null) { - fn = null; - } - if (typeof setters === 'string' && (fn != null)) { - name = setters; - (setters = {})[name] = fn; - } - return this.defineAttribute({ - setter: setters + HasManyRelation.prototype.initialize = function() { + var association, collection, foreignKey, name, owner, source, sourceAssociation, through, throughAssociation, to; + association = this.get('association'); + to = association.get('to'); + owner = this.get('owner'); + name = this.get('name'); + foreignKey = this.get('foreignKey'); + through = this.get('through'); + source = this.get('source'); + if (through == null) { + collection = to.all().where(foreignKey).is(owner.id); + collection.parent = owner; + this.getter({ + target: (function(_this) { + return function() { + return collection; + }; + })(this) }); - }, - lazy: function(attributes, fn) { - var key, name, _results; - if (fn == null) { - fn = null; - } - if (typeof attributes === 'string' && (fn != null)) { - name = attributes; - (attributes = {})[name] = fn; - } - _results = []; - for (key in attributes) { - fn = attributes[key]; - _results.push((function(_this) { - return function(key, fn) { - _this.getter(key, function() { - return _this.attributes[key] = (_this[fn] || fn).call(_this); - }); - return _this.setter(key, function(value) { - delete _this.attributes[key]; - return _this.attributes[key] = value; + return this.setter({ + target: (function(_this) { + return function(models) { + collection.each(function(model) { + return model.unset(foreignKey); }); + return collection.add(models); }; - })(this)(key, fn)); - } - return _results; - }, - defineAttribute: function(params) { - var attributes, fn, key, type, _results; - _results = []; - for (type in params) { - attributes = params[type]; - if (type === 'getter' || type === 'setter') { - _results.push((function() { - var _results1; - _results1 = []; - for (key in attributes) { - fn = attributes[key]; - _results1.push((function(_this) { - return function(key, fn) { - var map; - map = Object.getOwnPropertyDescriptor(_this.attributes, key) || { - configurable: true - }; - delete _this.attributes[key]; - delete map.value; - delete map.writable; - if (type === 'getter') { - map.get = function() { - return (_this[fn] || fn).call(_this); - }; - } else if (type === 'setter') { - map.set = function(value) { - var result; - return result = (_this[fn] || fn).call(_this, value); - }; - } - return Object.defineProperty(_this.attributes, key, map); + })(this) + }); + } else { + throughAssociation = owner.constructor.associations().findWhere({ + name: through + }); + if (throughAssociation.get('type') !== 'hasMany') { + return this.getter({ + target: (function(_this) { + return function() { + return owner.get(through).get(source || name); + }; + })(this) + }); + } else { + sourceAssociation = (source && throughAssociation.get('to').associations().findWhere({ + name: source + })) || throughAssociation.get('to').associations().findWhere({ + name: name, + type: 'hasMany' + }) || throughAssociation.get('to').associations().findWhere({ + name: inflection.singularize(name) + }); + if (sourceAssociation.get('type') === 'hasMany') { + source = sourceAssociation.get('name'); + return this.lazy({ + target: function() { + var union; + union = new Collection.Union(); + union.parent = owner; + owner.get(through).each((function(_this) { + return function(model) { + return union.addCollection(model.get(source)); }; - })(this)(key, fn)); + })(this)); + owner.get(through).on('add', (function(_this) { + return function(model) { + return union.addCollection(model.get(source)); + }; + })(this)); + owner.get(through).on('remove', (function(_this) { + return function(model) { + return union.removeCollection(model.get(source)); + }; + })(this)); + return union; } - return _results1; - }).call(this)); + }); + } else { + source = sourceAssociation.get('name'); + return this.lazy({ + target: function() { + return owner.get(through).pluck(source); + } + }); } } - return _results; } - }, - ClassMethods: { - getter: function(getters, fn) { - var name; - if (fn == null) { - fn = null; - } - if (typeof getters === 'string' && (fn != null)) { - name = getters; - (getters = {})[name] = fn; - } - return this.before({ - initialize: function() { - return this.getter(getters); - } + }; + + return HasManyRelation; + + })(Relation); + + module.exports = HasManyRelation; + +}).call(this); + +//# sourceMappingURL=has_many_relation.js.map + +},{"../collection":6,"./relation":5}],4:[function(require,module,exports){ +(function() { + var HasOneRelation, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Relation = require('./relation'); + + HasOneRelation = (function(_super) { + __extends(HasOneRelation, _super); + + function HasOneRelation() { + return HasOneRelation.__super__.constructor.apply(this, arguments); + } + + HasOneRelation.prototype.initialize = function() { + var association, foreignKey, owner, source, through, to; + owner = this.get('owner'); + association = this.get('association'); + to = association.get('to'); + foreignKey = this.get('foreignKey'); + through = this.get('through'); + source = this.get('source'); + if (through == null) { + this.getter({ + target: (function(_this) { + return function() { + return to.all().where(foreignKey).is(owner.id).first(); + }; + })(this) }); - }, - setter: function(setters, fn) { - var name; - if (fn == null) { - fn = null; - } - if (typeof setters === 'string' && (fn != null)) { - name = setters; - (setters = {})[name] = fn; - } - return this.before({ - initialize: function() { - return this.setter(setters); - } + this.setter({ + target: (function(_this) { + return function(model) { + var _ref; + if ((_ref = to.all().where(foreignKey).is(owner.id).first()) != null) { + _ref.unset(foreignKey); + } + return model.set(foreignKey, owner.id); + }; + })(this) }); - }, - lazy: function(attributes, fn) { - var name; - if (fn == null) { - fn = null; - } - if (typeof attributes === 'string' && (fn != null)) { - name = attributes; - (attributes = {})[name] = fn; - } - return this.before({ - initialize: function() { - return this.lazy(attributes); - } + } else { + this.getter({ + target: (function(_this) { + return function() { + return owner.get(through).get(source); + }; + })(this) + }); + this.setter({ + target: (function(_this) { + return function(model) { + return owner.get(through).set(source, model); + }; + })(this) }); - }, - extended: function() { - return this.concern(Tails.Mixins.Interceptable); } + return HasOneRelation.__super__.initialize.apply(this, arguments); + }; + + return HasOneRelation; + + })(Relation); + + module.exports = HasOneRelation; + +}).call(this); + +//# sourceMappingURL=has_one_relation.js.map + +},{"./relation":5}],5:[function(require,module,exports){ +(function() { + var Collectable, DynamicAttributes, Mixable, Relation, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Mixable = require('../mixable'); + + DynamicAttributes = require('../mixins/dynamic_attributes'); + + Collectable = require('../mixins/collectable'); + + Relation = (function(_super) { + __extends(Relation, _super); + + function Relation() { + return Relation.__super__.constructor.apply(this, arguments); } - }; - Tails.Collection = (function(_super) { + _.extend(Relation, Mixable); + + Relation.concern(DynamicAttributes); + + Relation.concern(Collectable); + + Relation.prototype.initialize = function() {}; + + return Relation; + + })(Backbone.Model); + + module.exports = Relation; + +}).call(this); + +//# sourceMappingURL=relation.js.map + +},{"../mixable":8,"../mixins/collectable":10,"../mixins/dynamic_attributes":12}],6:[function(require,module,exports){ +(function() { + var Collection, Mixable, Model, config, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Mixable = require('./mixable'); + + Model = require('./model'); + + config = require('./config'); + + Collection = (function(_super) { __extends(Collection, _super); - _.extend(Collection, Tails.Mixable); + _.extend(Collection, Mixable); Collection.prototype.syncedAt = 0; @@ -16592,7 +16334,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { if (options == null) { options = {}; } - this.model = options.model || this.model || Tails.Model; + this.model = options.model || this.model || Model; this.parent = options.parent || this.parent; this.synced = options.synced || false; this.on('change', (function(_this) { @@ -16615,7 +16357,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { Collection.prototype.url = function() { var base, format, root, url, _ref, _ref1; - base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || Tails.config.url; + base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || config.url; root = (typeof this.urlRoot === "function" ? this.urlRoot() : void 0) || this.urlRoot; format = this.format != null ? '.' + ((typeof this.format === "function" ? this.format() : void 0) || this.format) : ''; url = "" + base + "/" + root + format; @@ -16681,7 +16423,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }; Collection.prototype.filter = function(filter) { - return new Tails.Collection.Filtered(this, { + return new Collection.Filtered(this, { filter: filter }); }; @@ -16720,7 +16462,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } return _results; }; - return new Tails.Collection.Filtered(this, { + return new Collection.Filtered(this, { filter: filter, assimilate: assimilate, distantiate: distantiate @@ -16777,7 +16519,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }; Collection.prototype.pluck = function(attribute) { - return new Tails.Collection.Plucked(this, { + return new Collection.Plucked(this, { attribute: attribute }); }; @@ -16805,7 +16547,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { })(Backbone.Deferred.Collection); - Tails.Collection.Plucked = (function(_super) { + Collection.Plucked = (function(_super) { __extends(Plucked, _super); function Plucked(collection, options) { @@ -16896,9 +16638,9 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return Plucked; - })(Tails.Collection); + })(Collection); - Tails.Collection.Filtered = (function(_super) { + Collection.Filtered = (function(_super) { __extends(Filtered, _super); function Filtered(collection, options) { @@ -16971,9 +16713,9 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return Filtered; - })(Tails.Collection); + })(Collection); - Tails.Collection.Multi = (function(_super) { + Collection.Multi = (function(_super) { __extends(Multi, _super); function Multi(collections, options) { @@ -17030,47 +16772,306 @@ if ( typeof window === "object" && typeof window.document === "object" ) { if (!(index >= 0)) { return; } - this.collections = this.collections.slice(0, index).concat(this.collections.slice(index + 1, this.collections.length)); - collection.each((function(_this) { - return function(model) { - return _this.decrement(model); - }; - })(this)); - this.stopListening(collection); - return this.trigger('removeCollection', collection); - }; - - return Multi; - - })(Tails.Collection); - - Tails.Collection.Union = (function(_super) { - __extends(Union, _super); - - function Union() { - return Union.__super__.constructor.apply(this, arguments); + this.collections = this.collections.slice(0, index).concat(this.collections.slice(index + 1, this.collections.length)); + collection.each((function(_this) { + return function(model) { + return _this.decrement(model); + }; + })(this)); + this.stopListening(collection); + return this.trigger('removeCollection', collection); + }; + + return Multi; + + })(Collection); + + Collection.Union = (function(_super) { + __extends(Union, _super); + + function Union() { + return Union.__super__.constructor.apply(this, arguments); + } + + Union.prototype.increment = function(model) { + if (Union.__super__.increment.apply(this, arguments) === 1) { + return this.add(model); + } + }; + + Union.prototype.decrement = function(model) { + if (Union.__super__.decrement.apply(this, arguments) === 0) { + return this.remove(model); + } + }; + + return Union; + + })(Collection.Multi); + + module.exports = Collection; + +}).call(this); + +//# sourceMappingURL=collection.js.map + +},{"./config":7,"./mixable":8,"./model":16}],7:[function(require,module,exports){ +(function() { + module.exports = { + url: 'http://localhost' + }; + +}).call(this); + +//# sourceMappingURL=config.js.map + +},{}],8:[function(require,module,exports){ +(function() { + var Mixable, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, + __slice = [].slice; + + Mixable = { + MixableKeywords: ['included', 'extended', 'constructor', 'Interactions', 'InstanceMethods', 'ClassMethods'], + _include: function(mixin) { + var funcs, key, value, _ref; + if (mixin.InstanceMethods != null) { + funcs = mixin.InstanceMethods; + } else if (mixin.ClassMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this.prototype[key] = value; + } + } + } + return (_ref = funcs.included) != null ? _ref.apply(this) : void 0; + }, + _extend: function(mixin) { + var funcs, key, value, _ref; + if (mixin.ClassMethods != null) { + funcs = mixin.ClassMethods; + } else if (mixin.InstanceMethods != null) { + return; + } else { + funcs = mixin; + } + for (key in funcs) { + value = funcs[key]; + if (__indexOf.call(this.MixableKeywords, key) < 0) { + if (value != null) { + this[key] = value; + } + } + } + return (_ref = funcs.extended) != null ? _ref.apply(this) : void 0; + }, + include: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._includedMixins) != null ? _ref.klass : void 0) !== this) { + this._includedMixins = _(this._includedMixins).clone() || []; + this._includedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._includedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._includedMixins.push(mixin); + } + this._include(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + _ref1 = this._includedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._include(interactions); + } + } + } + return this; + }, + extend: function() { + var interactions, mixin, mixins, _i, _j, _len, _len1, _ref, _ref1; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (((_ref = this._extendedMixins) != null ? _ref.klass : void 0) !== this) { + this._extendedMixins = _(this._extendedMixins).clone() || []; + this._extendedMixins.klass = this; + } + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + if (__indexOf.call(this._extendedMixins, mixin) >= 0) { + continue; + } + if (mixin != null) { + this._extendedMixins.push(mixin); + } + this._extend(mixin); + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + _ref1 = this._extendedMixins; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + mixin = _ref1[_j]; + if (mixin.Interactions != null) { + interactions = mixin.Interactions.apply(this); + if (interactions != null) { + this._extend(interactions); + } + } + } + return this; + }, + "with": function(mixin, funcs) { + if (funcs == null) { + funcs = {}; + } + if ((this._includedMixins != null) && __indexOf.call(this._includedMixins, mixin) >= 0) { + return funcs; + } else if ((this._extendedMixins != null) && __indexOf.call(this._extendedMixins, mixin) >= 0) { + return funcs; + } else { + return null; + } + }, + concern: function() { + var mixin, mixins, _i, _len; + mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + for (_i = 0, _len = mixins.length; _i < _len; _i++) { + mixin = mixins[_i]; + this.include(mixin); + this.extend(mixin); + } + return this; + } + }; + + module.exports = Mixable; + +}).call(this); + +//# sourceMappingURL=mixable.js.map + +},{}],9:[function(require,module,exports){ +(function() { + var Associable, Association, Relation; + + Relation = require('../associations/relation'); + + Association = require('../associations/association'); + + Associable = { + InstanceMethods: { + relations: function() { + var Collection; + Collection = require('../collection'); + if (this._relations == null) { + this._relations = new Collection([], { + model: Relation + }); + } + return this._relations; + } + }, + ClassMethods: { + belongsTo: function(options) { + return this.associate('belongsTo', options); + }, + hasOne: function(options) { + return this.associate('hasOne', options); + }, + hasMany: function(options) { + return this.associate('hasMany', options); + }, + associate: function(type, options) { + var association, attrs, name, to; + name = _(options).keys()[0]; + to = options[name]; + attrs = { + type: type, + from: this, + name: name, + foreignKey: options.foreignKey, + through: options.through, + source: options.source + }; + association = new Association(attrs); + if (to.prototype instanceof Backbone.Model) { + return association.set({ + to: to + }); + } else { + return association.getter({ + to: to + }); + } + }, + associations: function() { + var _ref; + if (!((_ref = this._associations) != null ? _ref.klass = this : void 0)) { + this._associations = Association.all().where({ + from: this + }); + this._associations.klass = this; + } + return this._associations; + }, + extended: function() { + var Collectable, DynamicAttributes, Interceptable; + DynamicAttributes = require('./dynamic_attributes'); + Collectable = require('./collectable'); + Interceptable = require('./interceptable'); + this.concern(DynamicAttributes); + this.concern(Collectable); + this.concern(Interceptable); + return this.before({ + initialize: function() { + return this.constructor.associations().each((function(_this) { + return function(association) { + return association.apply(_this); + }; + })(this)); + } + }); + } } + }; - Union.prototype.increment = function(model) { - if (Union.__super__.increment.apply(this, arguments) === 1) { - return this.add(model); - } - }; + module.exports = Associable; - Union.prototype.decrement = function(model) { - if (Union.__super__.decrement.apply(this, arguments) === 0) { - return this.remove(model); - } - }; +}).call(this); - return Union; +//# sourceMappingURL=associable.js.map + +},{"../associations/association":1,"../associations/relation":5,"../collection":6,"./collectable":10,"./dynamic_attributes":12,"./interceptable":14}],10:[function(require,module,exports){ +(function() { + var Collectable, Interceptable; - })(Tails.Collection.Multi); + Interceptable = require('./interceptable'); - Tails.Mixins.Collectable = { + Collectable = { InstanceMethods: { included: function() { - this.concern(Tails.Mixins.Interceptable); + this.concern(Interceptable); return this.after({ initialize: function() { if ((this.id != null) && (this.constructor.all().get(this.id) != null)) { @@ -17083,9 +17084,10 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }, ClassMethods: { all: function() { - var _ref; + var Collection, _ref; + Collection = require('../collection'); if (((_ref = this._all) != null ? _ref.klass : void 0) !== this) { - this._all = new Tails.Collection(null, { + this._all = new Collection(null, { model: this }); this._all.klass = this; @@ -17102,8 +17104,10 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }, Interactions: function() { + var Storage; + Storage = require('./storage'); return { - ClassMethods: this["with"](Tails.Mixins.Storage, { + ClassMethods: this["with"](Storage, { extended: function() { return this.all().on('add remove', (function(_this) { return function(instance) { @@ -17118,370 +17122,581 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Tails.Associations.Relation = (function(_super) { - __extends(Relation, _super); - - function Relation() { - return Relation.__super__.constructor.apply(this, arguments); - } - - _.extend(Relation, Tails.Mixable); - - Relation.concern(Tails.Mixins.DynamicAttributes); + module.exports = Collectable; - Relation.concern(Tails.Mixins.Collectable); - - Relation.prototype.initialize = function() {}; - - return Relation; +}).call(this); - })(Backbone.Model); +//# sourceMappingURL=collectable.js.map - Tails.Associations.BelongsToRelation = (function(_super) { - __extends(BelongsToRelation, _super); +},{"../collection":6,"./interceptable":14,"./storage":15}],11:[function(require,module,exports){ +(function() { + var Debug, Interceptable, + __slice = [].slice, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - function BelongsToRelation() { - return BelongsToRelation.__super__.constructor.apply(this, arguments); - } + Interceptable = require('./interceptable'); - BelongsToRelation.prototype.initialize = function() { - var association, foreignKey, owner, to; - association = this.get('association'); - to = association.get('to'); - foreignKey = this.get('foreignKey'); - owner = this.get('owner'); - this.getter({ - target: function() { - return to.get(owner.get(foreignKey)); - } - }); - this.setter({ - target: function(model) { - if (model == null) { - this.set(foreignKey, null); - return; - } - if (to.all().get(model.id) == null) { - to.all().add(model, { - parse: true - }); + Debug = { + InstanceMethods: { + LOG_LEVELS: { + "ERROR": true, + "WARNING": true, + "INFO": false + }, + _excludedMethods: _.union(Object.keys(Interceptable.InstanceMethods), ["constructor", "log", "message", "warn", "error", "info"]), + debug: function() { + return this.LOG_LEVELS.INFO = true; + }, + message: function() { + var line, thing, things, _i, _len; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = "" + (new Date()) + " - "; + for (_i = 0, _len = things.length; _i < _len; _i++) { + thing = things[_i]; + if (thing.constructor.name === "String") { + line += thing + " "; + } else { + line += JSON.stringify(thing) + " "; } - return owner.set(foreignKey, model.id); } - }); - return BelongsToRelation.__super__.initialize.apply(this, arguments); - }; + line += "in " + this.constructor.name + "(" + this.id + ")"; + return line; + }, + error: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.ERROR) { + return; + } + line = this.message.apply(this, things); + return console.error(line); + }, + warn: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.WARNING) { + return; + } + line = this.message.apply(this, things); + return console.warn(line); + }, + log: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + line = this.message.apply(this, things); + return console.log(line); + }, + info: function() { + var line, things; + things = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (!this.LOG_LEVELS.INFO) { + return; + } + line = this.message.apply(this, things); + return console.log(line); + }, + included: function() { + this.concern(Interceptable); + return this.after({ + initialize: function() { + var args, funcs, key, value, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + this.info("Called function 'initialize' of " + this.constructor.name + " with arguments:", args); + this.on("change", (function(_this) { + return function(event) { + return _this.info("Change of attributes:", event.changedAttributes()); + }; + })(this)); + funcs = (function() { + var _results; + _results = []; + for (key in this) { + value = this[key]; + if (value instanceof Function && __indexOf.call(this._excludedMethods, key) < 0) { + _results.push(key); + } else { + continue; + } + } + return _results; + }).call(this); + _results = []; + for (_i = 0, _len = funcs.length; _i < _len; _i++) { + key = funcs[_i]; + _results.push((function(_this) { + return function(key) { + return _this.after({ + "these": [key], + "do": function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return this.info("Called function '" + key + "' of " + this.constructor.name + " with arguments:", args); + } + }); + }; + })(this)(key)); + } + return _results; + } + }); + } + } + }; - return BelongsToRelation; + module.exports = Debug; - })(Tails.Associations.Relation); +}).call(this); - Tails.Associations.HasOneRelation = (function(_super) { - __extends(HasOneRelation, _super); +//# sourceMappingURL=debug.js.map - function HasOneRelation() { - return HasOneRelation.__super__.constructor.apply(this, arguments); - } +},{"./interceptable":14}],12:[function(require,module,exports){ +(function() { + var DynamicAttributes, Interceptable; - HasOneRelation.prototype.initialize = function() { - var association, foreignKey, owner, source, through, to; - owner = this.get('owner'); - association = this.get('association'); - to = association.get('to'); - foreignKey = this.get('foreignKey'); - through = this.get('through'); - source = this.get('source'); - if (through == null) { - this.getter({ - target: (function(_this) { - return function() { - return to.all().where(foreignKey).is(owner.id).first(); + Interceptable = require('./interceptable'); + + DynamicAttributes = { + InstanceMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.defineAttribute({ + getter: getters + }); + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.defineAttribute({ + setter: setters + }); + }, + lazy: function(attributes, fn) { + var key, name, _results; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + _results = []; + for (key in attributes) { + fn = attributes[key]; + _results.push((function(_this) { + return function(key, fn) { + _this.getter(key, function() { + return _this.attributes[key] = (_this[fn] || fn).call(_this); + }); + return _this.setter(key, function(value) { + delete _this.attributes[key]; + return _this.attributes[key] = value; + }); }; - })(this) - }); - this.setter({ - target: (function(_this) { - return function(model) { - var _ref; - if ((_ref = to.all().where(foreignKey).is(owner.id).first()) != null) { - _ref.unset(foreignKey); + })(this)(key, fn)); + } + return _results; + }, + defineAttribute: function(params) { + var attributes, fn, key, type, _results; + _results = []; + for (type in params) { + attributes = params[type]; + if (type === 'getter' || type === 'setter') { + _results.push((function() { + var _results1; + _results1 = []; + for (key in attributes) { + fn = attributes[key]; + _results1.push((function(_this) { + return function(key, fn) { + var map; + map = Object.getOwnPropertyDescriptor(_this.attributes, key) || { + configurable: true + }; + delete _this.attributes[key]; + delete map.value; + delete map.writable; + if (type === 'getter') { + map.get = function() { + return (_this[fn] || fn).call(_this); + }; + } else if (type === 'setter') { + map.set = function(value) { + var result; + return result = (_this[fn] || fn).call(_this, value); + }; + } + return Object.defineProperty(_this.attributes, key, map); + }; + })(this)(key, fn)); } - return model.set(foreignKey, owner.id); - }; - })(this) + return _results1; + }).call(this)); + } + } + return _results; + } + }, + ClassMethods: { + getter: function(getters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof getters === 'string' && (fn != null)) { + name = getters; + (getters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.getter(getters); + } }); - } else { - this.getter({ - target: (function(_this) { - return function() { - return owner.get(through).get(source); - }; - })(this) + }, + setter: function(setters, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof setters === 'string' && (fn != null)) { + name = setters; + (setters = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.setter(setters); + } }); - this.setter({ - target: (function(_this) { - return function(model) { - return owner.get(through).set(source, model); - }; - })(this) + }, + lazy: function(attributes, fn) { + var name; + if (fn == null) { + fn = null; + } + if (typeof attributes === 'string' && (fn != null)) { + name = attributes; + (attributes = {})[name] = fn; + } + return this.before({ + initialize: function() { + return this.lazy(attributes); + } }); + }, + extended: function() { + return this.concern(Interceptable); } - return HasOneRelation.__super__.initialize.apply(this, arguments); - }; + } + }; - return HasOneRelation; + module.exports = DynamicAttributes; - })(Tails.Associations.Relation); +}).call(this); - Tails.Associations.HasManyRelation = (function(_super) { - __extends(HasManyRelation, _super); +//# sourceMappingURL=dynamic_attributes.js.map - function HasManyRelation() { - return HasManyRelation.__super__.constructor.apply(this, arguments); - } +},{"./interceptable":14}],13:[function(require,module,exports){ +(function() { + var History, Storage; - HasManyRelation.prototype.initialize = function() { - var association, collection, foreignKey, name, owner, source, sourceAssociation, through, throughAssociation, to; - association = this.get('association'); - to = association.get('to'); - owner = this.get('owner'); - name = this.get('name'); - foreignKey = this.get('foreignKey'); - through = this.get('through'); - source = this.get('source'); - if (through == null) { - collection = to.all().where(foreignKey).is(owner.id); - collection.parent = owner; - this.getter({ - target: (function(_this) { - return function() { - return collection; - }; - })(this) - }); - return this.setter({ - target: (function(_this) { - return function(models) { - collection.each(function(model) { - return model.unset(foreignKey); - }); - return collection.add(models); - }; - })(this) - }); - } else { - throughAssociation = owner.constructor.associations().findWhere({ - name: through - }); - if (throughAssociation.get('type') !== 'hasMany') { - return this.getter({ - target: (function(_this) { - return function() { - return owner.get(through).get(source || name); + Storage = require('./storage'); + + History = { + Interactions: function() { + return { + InstanceMethods: this["with"](Storage, { + diff: function() { + var diff, key, prevAttrs, value, _ref; + diff = {}; + diff.apply = (function(_this) { + return function(context) { + var change, key, type, values; + if (context == null) { + context = _this; + } + for (key in diff) { + change = diff[key]; + for (type in change) { + values = change[type]; + switch (type) { + case "create": + context.set(key, values["value"]); + break; + case "update": + context.set(key, values["new"]); + break; + case "delete": + context.unset(key); + } + } + } + return context; }; - })(this) - }); - } else { - sourceAssociation = (source && throughAssociation.get('to').associations().findWhere({ - name: source - })) || throughAssociation.get('to').associations().findWhere({ - name: name, - type: 'hasMany' - }) || throughAssociation.get('to').associations().findWhere({ - name: inflection.singularize(name) - }); - if (sourceAssociation.get('type') === 'hasMany') { - source = sourceAssociation.get('name'); - return this.lazy({ - target: function() { - var union; - union = new Tails.Collection.Union(); - union.parent = owner; - owner.get(through).each((function(_this) { - return function(model) { - return union.addCollection(model.get(source)); - }; - })(this)); - owner.get(through).on('add', (function(_this) { - return function(model) { - return union.addCollection(model.get(source)); + })(this); + prevAttrs = this.constructor.retrieve(this.id) || {}; + _ref = this.attributes; + for (key in _ref) { + value = _ref[key]; + if (prevAttrs[key] !== this.get(key)) { + if (prevAttrs[key] != null) { + diff[key] = { + "update": { + "old": prevAttrs[key], + "new": this.get(key) + } }; - })(this)); - owner.get(through).on('remove', (function(_this) { - return function(model) { - return union.removeCollection(model.get(source)); + } else { + diff[key] = { + "create": { + "value": this.get(key) + } }; - })(this)); - return union; + } } - }); - } else { - source = sourceAssociation.get('name'); - return this.lazy({ - target: function() { - return owner.get(through).pluck(source); + } + for (key in prevAttrs) { + value = prevAttrs[key]; + if (!this.has(key)) { + diff[key] = { + "delete": { + "value": value + } + }; + } + } + return diff; + }, + commit: function() { + var key; + key = this.store(this.diff()); + return key; + }, + included: function() { + return this.after({ + initialize: function() { + return this.on("change", this.commit); } }); } - } - } - }; - - return HasManyRelation; - - })(Tails.Associations.Relation); - - Tails.Associations.Association = (function(_super) { - __extends(Association, _super); - - function Association() { - return Association.__super__.constructor.apply(this, arguments); + }) + }; } + }; - _.extend(Association, Tails.Mixable); + module.exports = History; - Association.concern(Tails.Mixins.Debug); +}).call(this); - Association.concern(Tails.Mixins.DynamicAttributes); +//# sourceMappingURL=history.js.map - Association.concern(Tails.Mixins.Collectable); +},{"./storage":15}],14:[function(require,module,exports){ +(function() { + var Interceptable, + __slice = [].slice; - Association.prototype.relations = function() { - if (this._relations == null) { - this._relations = new Tails.Collection([], { - model: Tails.Associations.Relation + Interceptable = { + InstanceMethods: { + before: function(interceptors) { + return this.intercept({ + before: interceptors }); - } - return this._relations; - }; - - Association.prototype.apply = function(owner) { - var attrs, model, models, relation; - attrs = { - association: this, - from: this.get('from'), - to: this.get('to'), - name: this.get('name'), - owner: owner - }; - switch (this.get('type')) { - case 'belongsTo': - model = owner.get(attrs.name); - relation = new Tails.Associations.BelongsToRelation(_.extend(attrs, { - foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.to.name || attrs.to.toString().match(/^function\s*([^\s(]+)/)[1]) - })); - if (model != null) { - relation.set("target", model); - } - break; - case 'hasOne': - model = owner.get(attrs.name); - relation = new Tails.Associations.HasOneRelation(_.extend(attrs, { - foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), - through: this.get('through'), - source: this.get('source') || this.get('name') - })); - if (model != null) { - relation.set("target", model); + }, + after: function(interceptors) { + return this.intercept({ + after: interceptors + }); + }, + intercept: function(params) { + var fn, fns, interceptors, k, key, klass, placement, v, _i, _len, _ref, _results; + klass = this.constructor; + _results = []; + for (placement in params) { + interceptors = params[placement]; + if (!(placement === 'before' || placement === 'after')) { + continue; } - break; - case 'hasMany': - models = owner.get(attrs.name); - relation = new Tails.Associations.HasManyRelation(_.extend(attrs, { - foreignKey: this.get('foreignKey') || inflection.foreign_key(attrs.from.name || attrs.from.toString().match(/^function\s*([^\s(]+)/)[1]), - through: this.get('through'), - source: this.get('source') || this.get('name') - })); - if (models != null) { - relation.set("target", models); + if (interceptors.these != null) { + _ref = interceptors.these; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + if (typeof key === 'function') { + for (k in this) { + v = this[k]; + if (key === v) { + key = k; + break; + } + } + } + interceptors[key] = interceptors["do"]; + } } - } - this.relations().add(relation); - owner.relations().add(relation); - owner.getter(attrs.name, function() { - return relation.get('target'); - }); - return owner.setter(attrs.name, function(value) { - return relation.set('target', value); - }); - }; - - return Association; - - })(Backbone.Model); - - Tails.Mixins.Associable = { - InstanceMethods: { - relations: function() { - if (this._relations == null) { - this._relations = new Tails.Collection([], { - model: Tails.Associations.Relation - }); + interceptors = _(interceptors).omit('these', 'do'); + _results.push((function() { + var _results1; + _results1 = []; + for (key in interceptors) { + fns = interceptors[key]; + if (!_(fns).isArray()) { + fns = [fns]; + } + _results1.push((function() { + var _j, _len1, _results2; + _results2 = []; + for (_j = 0, _len1 = fns.length; _j < _len1; _j++) { + fn = fns[_j]; + _results2.push((function(_this) { + return function(key, fn) { + var after, before, interceptable, prev, _ref1, _ref2, _ref3, _ref4; + if ((_this.hasOwnProperty(key) || klass.prototype.hasOwnProperty(key)) && !((_this[key].before != null) || (_this[key].after != null))) { + interceptable = _this[key]; + return _this[key] = function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (placement === 'before') { + (this[fn] || fn).apply(this, args); + } + ret = interceptable.apply(this, args); + if (placement === 'after') { + (this[fn] || fn).apply(this, args); + } + return ret; + }; + } else { + before = ((_ref1 = _this[key]) != null ? _ref1.klass : void 0) === klass ? (_ref2 = _this[key]) != null ? _ref2.before : void 0 : void 0; + after = ((_ref3 = _this[key]) != null ? _ref3.klass : void 0) === klass ? (_ref4 = _this[key]) != null ? _ref4.after : void 0 : void 0; + if (placement === 'before') { + prev = before; + before = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (prev != null) { + prev.apply(this, args); + } + return (this[fn] || fn).apply(this, args); + }; + } else if (placement === 'after') { + prev = after; + after = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + (this[fn] || fn).apply(this, args); + return prev != null ? prev.apply(this, args) : void 0; + }; + } + return Object.defineProperty(_this, key, { + configurable: true, + set: function(interceptable) { + return Object.defineProperty(this, key, { + writable: true, + value: function() { + var args, ret; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + ret = interceptable.apply(this, args); + if (after != null) { + after.apply(this, args); + } + return ret; + } + }); + }, + get: function() { + var interceptor; + interceptor = function() { + var args, ret, superFn, _ref5; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (before != null) { + before.apply(this, args); + } + superFn = (_ref5 = this.constructor.__super__) != null ? _ref5[key] : void 0; + if ((superFn != null ? superFn.klass : void 0) !== klass) { + ret = superFn != null ? superFn.apply(this, args) : void 0; + } + if (after != null) { + after.apply(this, args); + } + return ret; + }; + interceptor.before = before; + interceptor.after = after; + interceptor.klass = klass; + return interceptor; + } + }); + } + }; + })(this)(key, fn)); + } + return _results2; + }).call(this)); + } + return _results1; + }).call(this)); } - return this._relations; - } - }, - ClassMethods: { - belongsTo: function(options) { - return this.associate('belongsTo', options); - }, - hasOne: function(options) { - return this.associate('hasOne', options); - }, - hasMany: function(options) { - return this.associate('hasMany', options); - }, - associate: function(type, options) { - var association, attrs, name, to; - name = _(options).keys()[0]; - to = options[name]; - attrs = { - type: type, - from: this, - name: name, - foreignKey: options.foreignKey, - through: options.through, - source: options.source - }; - association = new Tails.Associations.Association(attrs); - if (to.prototype instanceof Backbone.Model) { - return association.set({ - to: to + return _results; + } + }, + ClassMethods: { + before: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.before(interceptors.call(this)); + } }); } else { - return association.getter({ - to: to - }); + return this.prototype.before(interceptors); } }, - associations: function() { - var _ref; - if (!((_ref = this._associations) != null ? _ref.klass = this : void 0)) { - this._associations = Tails.Associations.Association.all().where({ - from: this + after: function(interceptors) { + if ((typeof interceptors === "function" ? interceptors() : void 0) != null) { + return this.before({ + initialize: function() { + return this.after(interceptors.call(this)); + } }); - this._associations.klass = this; + } else { + return this.prototype.after(interceptors); } - return this._associations; - }, - extended: function() { - this.concern(Tails.Mixins.DynamicAttributes); - this.concern(Tails.Mixins.Collectable); - this.concern(Tails.Mixins.Interceptable); - return this.before({ - initialize: function() { - return this.constructor.associations().each((function(_this) { - return function(association) { - return association.apply(_this); - }; - })(this)); - } - }); } } }; - Tails.Mixins.Storage = { + module.exports = Interceptable; + +}).call(this); + +//# sourceMappingURL=interceptable.js.map + +},{}],15:[function(require,module,exports){ +(function() { + var Collectable, Debug, Hash, Interceptable, Storage; + + Interceptable = require('./interceptable'); + + Hash = require('../utils/hash'); + + Debug = require('./debug'); + + Collectable = require('./collectable'); + + Storage = { InstanceMethods: { storage: function() { return this.constructor.storage(); @@ -17496,7 +17711,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return _.defaults(this.attributes, this.constructor.retrieve(this.id, hash)); }, included: function() { - this.concern(Tails.Mixins.Interceptable); + this.concern(Interceptable); return this.after({ initialize: function() { this.on("sync", this.store); @@ -17524,7 +17739,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { indexRoot = (_ref = typeof this.indexRoot === "function" ? this.indexRoot() : void 0) != null ? _ref : this.indexRoot; key = "" + indexRoot + "/" + instance.id; if (data != null) { - key += "/" + Tails.Utils.Hash(this.toJSON(data)); + key += "/" + Hash(this.toJSON(data)); json = this.toJSON({ "instance": instance, "data": data @@ -17548,7 +17763,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return JSON.parse(json); } } else { - json = this.storage().getItem(Tails.Utils.Hash(indexRoot)); + json = this.storage().getItem(Hash(indexRoot)); ids = JSON.parse(json); if (json != null) { for (_i = 0, _len = ids.length; _i < _len; _i++) { @@ -17562,7 +17777,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }, Interactions: function() { return { - InstanceMethods: this["with"](Tails.Mixins.Debug, { + InstanceMethods: this["with"](Debug, { included: (function(_this) { return function() { return _this.after({ @@ -17578,7 +17793,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { }; })(this) }), - ClassMethods: this["with"](Tails.Mixins.Collectable, { + ClassMethods: this["with"](Collectable, { indexRoot: function() { var _ref; return (_ref = typeof this.urlRoot === "function" ? this.urlRoot() : void 0) != null ? _ref : this.urlRoot; @@ -17598,98 +17813,35 @@ if ( typeof window === "object" && typeof window.document === "object" ) { } }; - Tails.Mixins.History = { - Interactions: function() { - return { - InstanceMethods: this["with"](Tails.Mixins.Storage, { - diff: function() { - var diff, key, prevAttrs, value, _ref; - diff = {}; - diff.apply = (function(_this) { - return function(context) { - var change, key, type, values; - if (context == null) { - context = _this; - } - for (key in diff) { - change = diff[key]; - for (type in change) { - values = change[type]; - switch (type) { - case "create": - context.set(key, values["value"]); - break; - case "update": - context.set(key, values["new"]); - break; - case "delete": - context.unset(key); - } - } - } - return context; - }; - })(this); - prevAttrs = this.constructor.retrieve(this.id) || {}; - _ref = this.attributes; - for (key in _ref) { - value = _ref[key]; - if (prevAttrs[key] !== this.get(key)) { - if (prevAttrs[key] != null) { - diff[key] = { - "update": { - "old": prevAttrs[key], - "new": this.get(key) - } - }; - } else { - diff[key] = { - "create": { - "value": this.get(key) - } - }; - } - } - } - for (key in prevAttrs) { - value = prevAttrs[key]; - if (!this.has(key)) { - diff[key] = { - "delete": { - "value": value - } - }; - } - } - return diff; - }, - commit: function() { - var key; - key = this.store(this.diff()); - return key; - }, - included: function() { - return this.after({ - initialize: function() { - return this.on("change", this.commit); - } - }); - } - }) - }; - } - }; + module.exports = Storage; + +}).call(this); + +//# sourceMappingURL=storage.js.map + +},{"../utils/hash":19,"./collectable":10,"./debug":11,"./interceptable":14}],16:[function(require,module,exports){ +(function() { + var Associable, Mixable, Model, config, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice; + + Mixable = require('./mixable'); + + Associable = require('./mixins/associable'); - Tails.Model = (function(_super) { + config = require('./config'); + + Model = (function(_super) { __extends(Model, _super); function Model() { return Model.__super__.constructor.apply(this, arguments); } - _.extend(Model, Tails.Mixable); + _.extend(Model, Mixable); - Model.concern(Tails.Mixins.Associable); + Model.concern(Associable); Model.prototype.syncedAt = 0; @@ -17723,7 +17875,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) { Model.prototype.url = function() { var base, format, id, root, url, _ref, _ref1; - base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || Tails.config.url; + base = ((_ref = this.parent) != null ? typeof _ref.url === "function" ? _ref.url() : void 0 : void 0) || ((_ref1 = this.parent) != null ? _ref1.url : void 0) || config.url; root = (typeof this.urlRoot === "function" ? this.urlRoot() : void 0) || this.urlRoot; id = this.id ? "/" + this.id : ''; format = this.format != null ? '.' + ((typeof this.format === "function" ? this.format() : void 0) || this.format) : ''; @@ -17802,14 +17954,122 @@ if ( typeof window === "object" && typeof window.document === "object" ) { })(Backbone.Deferred.Model); - Tails.Template = (function(_super) { + module.exports = Model; + +}).call(this); + +//# sourceMappingURL=model.js.map + +},{"./config":7,"./mixable":8,"./mixins/associable":9}],17:[function(require,module,exports){ +(function() { + var Associable, Association, BelongsToRelation, Collectable, Collection, Debug, DynamicAttributes, HasManyRelation, HasOneRelation, Hash, History, Interceptable, Mixable, Model, Relation, Storage, Tails, Template, View, config; + + require('./utils/rivets-tails'); + + Hash = require('./utils/hash'); + + Mixable = require('./mixable'); + + Interceptable = require('./mixins/interceptable'); + + Debug = require('./mixins/debug'); + + DynamicAttributes = require('./mixins/dynamic_attributes'); + + Collectable = require('./mixins/collectable'); + + Associable = require('./mixins/associable'); + + Storage = require('./mixins/storage'); + + History = require('./mixins/history'); + + Collection = require('./collection'); + + Association = require('./associations/association'); + + Relation = require('./associations/relation'); + + BelongsToRelation = require('./associations/belongs_to_relation'); + + HasOneRelation = require('./associations/has_one_relation'); + + HasManyRelation = require('./associations/has_many_relation'); + + Model = require('./model'); + + Template = require('./template'); + + View = require('./view'); + + config = require('./config'); + + Tails = { + Mixins: {}, + Utils: {}, + Associations: {}, + Models: {}, + Views: {} + }; + + Tails.Utils = { + Hash: Hash + }; + + Tails.Mixable = Mixable; + + Tails.Mixins = { + Interceptable: Interceptable, + Collectable: Collectable, + Associable: Associable, + Debug: Debug, + DynamicAttributes: DynamicAttributes, + Storage: Storage, + History: History + }; + + Tails.Collection = Collection; + + Tails.Associations = { + Relation: Relation, + Association: Association, + BelongsToRelation: BelongsToRelation, + HasOneRelation: HasOneRelation, + HasManyRelation: HasManyRelation + }; + + Tails.Model = Model; + + Tails.View = View; + + Tails.Template = Template; + + Tails.config = config; + + module.exports = Tails; + +}).call(this); + +//# sourceMappingURL=tails.js.map + +},{"./associations/association":1,"./associations/belongs_to_relation":2,"./associations/has_many_relation":3,"./associations/has_one_relation":4,"./associations/relation":5,"./collection":6,"./config":7,"./mixable":8,"./mixins/associable":9,"./mixins/collectable":10,"./mixins/debug":11,"./mixins/dynamic_attributes":12,"./mixins/history":13,"./mixins/interceptable":14,"./mixins/storage":15,"./model":16,"./template":18,"./utils/hash":19,"./utils/rivets-tails":20,"./view":21}],18:[function(require,module,exports){ +(function() { + var Collectable, Model, Template, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Collectable = require('./mixins/collectable'); + + Model = require('./model'); + + Template = (function(_super) { __extends(Template, _super); function Template() { return Template.__super__.constructor.apply(this, arguments); } - Template.concern(Tails.Mixins.Collectable); + Template.concern(Collectable); Template.prototype.urlRoot = 'assets'; @@ -17836,23 +18096,96 @@ if ( typeof window === "object" && typeof window.document === "object" ) { return Template; - })(Tails.Model); + })(Model); + + module.exports = Collectable; + +}).call(this); + +//# sourceMappingURL=template.js.map + +},{"./mixins/collectable":10,"./model":16}],19:[function(require,module,exports){ +(function() { + var Hash; + + Hash = function(string) { + var char, hash, i, _i, _ref; + hash = 0; + if (string.length === 0) { + return hash; + } + for (i = _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + char = string.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; + } + return hash; + }; + + module.exports = Hash; + +}).call(this); + +//# sourceMappingURL=hash.js.map + +},{}],20:[function(require,module,exports){ +(function() { + if (typeof rivets !== "undefined" && rivets !== null) { + rivets.adapters[':'] = { + subscribe: function(obj, keypath, callback) { + if (obj instanceof Backbone.Collection) { + obj.on('add remove reset', callback); + } + return obj.on('change:' + keypath, callback); + }, + unsubscribe: function(obj, keypath, callback) { + if (obj instanceof Backbone.Collection) { + obj.off('add remove reset', callback); + } + return obj.off('change:' + keypath, callback); + }, + read: function(obj, keypath) { + if (obj instanceof Backbone.Collection) { + return obj.models; + } else { + return obj.get(keypath); + } + }, + publish: function(obj, keypath, value) { + return obj.set(keypath, value); + } + }; + } + +}).call(this); + +//# sourceMappingURL=rivets-tails.js.map + +},{}],21:[function(require,module,exports){ +(function() { + var Mixable, Template, View, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + Mixable = require('./mixable'); - Tails.View = (function(_super) { + Template = require('./template'); + + View = (function(_super) { __extends(View, _super); function View() { return View.__super__.constructor.apply(this, arguments); } - _.extend(View, Tails.Mixable); + _.extend(View, Mixable); View.prototype.initialize = function(options) { if (options == null) { options = {}; } if (this.template.constructor === String) { - this.template = Tails.Template.get(this.template); + this.template = Template.get(this.template); } this.template.bind(this).then((function(_this) { return function($el) { @@ -17876,43 +18209,11 @@ if ( typeof window === "object" && typeof window.document === "object" ) { })(Backbone.View); - Tails.factory = function(exports) { - exports._ = Tails; - exports.Mixable = Tails.Mixable; - exports.Model = Tails.Model; - exports.Collection = Tails.Collection; - exports.View = Tails.View; - exports.Template = Tails.Template; - exports.Mixins = Tails.Mixins; - exports.Utils = Tails.Utils; - exports.Association = Tails.Association; - exports.Associations = Tails.Associations; - exports.Models = Tails.Models; - exports.Views = Tails.Views; - exports.config = Tails.config; - return exports.configure = function(options) { - var property, value; - if (options == null) { - options = {}; - } - for (property in options) { - value = options[property]; - Tails.config[property] = value; - } - }; - }; - - if (typeof exports === 'object') { - Tails.factory(exports); - } else if (typeof define === 'function' && define.amd) { - define(['exports'], function(exports) { - Tails.factory(this.Tails = exports); - return exports; - }); - } else { - Tails.factory(this.Tails = {}); - } + module.exports = View; }).call(this); -//# sourceMappingURL=tails.js.map +//# sourceMappingURL=view.js.map + +},{"./mixable":8,"./template":18}]},{},[17])(17) +}); \ No newline at end of file diff --git a/dist/tails.bundle.min.js b/dist/tails.bundle.min.js index 68f4aac..f4a0ef9 100644 --- a/dist/tails.bundle.min.js +++ b/dist/tails.bundle.min.js @@ -1,11 +1,7 @@ -// Tails -// version: 0.1.0 -// contributors: Joost Verdoorn,Steffan Sluis -// license: MIT (function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.push,h=d.slice,i=d.concat,j=e.toString,k=e.hasOwnProperty,l=d.forEach,m=d.map,n=d.reduce,o=d.reduceRight,p=d.filter,q=d.every,r=d.some,s=d.indexOf,t=d.lastIndexOf,u=Array.isArray,v=Object.keys,w=f.bind,x=function(a){return a instanceof x?a:this instanceof x?void(this._wrapped=a):new x(a)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.5.2";var y=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g=x.keys(a),e=0,f=g.length;f>e;e++)if(b.call(d,a[g[e]],g[e],a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d.push(b.call(c,a,e,f))}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&d.push(a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?void 0:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;gd||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index-b.index}),"value")};var C=function(a){return function(b,c,d){var e={},f=null==c?x.identity:B(c);return y(b,function(c,g){var h=f.call(d,c,g,b);a(e,h,c)}),e}};x.groupBy=C(function(a,b,c){(x.has(a,b)?a[b]:a[b]=[]).push(c)}),x.indexBy=C(function(a,b,c){a[b]=c}),x.countBy=C(function(a,b){x.has(a,b)?a[b]++:a[b]=1}),x.sortedIndex=function(a,b,c,d){c=null==c?x.identity:B(c);for(var e=c.call(d,b),f=0,g=a.length;g>f;){var h=f+g>>>1;c.call(d,a[h])=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=x.max(x.pluck(arguments,"length").concat(0)),b=new Array(a),c=0;a>c;c++)b[c]=x.pluck(arguments,""+c);return b},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);d>e;)f[e++]=a,a+=c;return f};var E=function(){};x.bind=function(a,b){var c,d;if(w&&a.bind===w)return w.apply(a,h.call(arguments,1));if(!x.isFunction(a))throw new TypeError;return c=h.call(arguments,2),d=function(){if(!(this instanceof d))return a.apply(b,c.concat(h.call(arguments)));E.prototype=a.prototype;var e=new E;E.prototype=null;var f=a.apply(e,c.concat(h.call(arguments)));return Object(f)===f?f:e}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);if(0===b.length)throw new Error("bindAll must be passed function names");return y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b,c){var d,e,f,g=null,h=0;c||(c={});var i=function(){h=c.leading===!1?0:new Date,g=null,f=a.apply(d,e)};return function(){var j=new Date;h||c.leading!==!1||(h=j);var k=b-(j-h);return d=this,e=arguments,0>=k?(clearTimeout(g),g=null,h=j,f=a.apply(d,e)):g||c.trailing===!1||(g=setTimeout(i,k)),f}},x.debounce=function(a,b,c){var d,e,f,g,h;return function(){f=this,e=arguments,g=new Date;var i=function(){var j=new Date-g;b>j?d=setTimeout(i,b-j):(d=null,c||(h=a.apply(f,e)))},j=c&&!d;return d||(d=setTimeout(i,b)),j&&(h=a.apply(f,e)),h}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return function(){return--a<1?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&b.push(c);return b},x.values=function(a){for(var b=x.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=a[b[e]];return d},x.pairs=function(a){for(var b=x.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=[b[e],a[b[e]]];return d},x.invert=function(a){for(var b={},c=x.keys(a),d=0,e=c.length;e>d;d++)b[a[c[d]]]=c[d];return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)void 0===a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var F=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;var g=a.constructor,h=b.constructor;if(g!==h&&!(x.isFunction(g)&&g instanceof g&&x.isFunction(h)&&h instanceof h))return!1;c.push(a),d.push(b);var i=0,k=!0;if("[object Array]"==e){if(i=a.length,k=i==b.length)for(;i--&&(k=F(a[i],b[i],c,d)););}else{for(var l in a)if(x.has(a,l)&&(i++,!(k=x.has(b,l)&&F(a[l],b[l],c,d))))break;if(k){for(l in b)if(x.has(b,l)&&!i--)break;k=!i}}return c.pop(),d.pop(),k};x.isEqual=function(a,b){return F(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(Math.max(0,a)),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var G={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};G.unescape=x.invert(G.escape);var H={escape:new RegExp("["+x.keys(G.escape).join("")+"]","g"),unescape:new RegExp("("+x.keys(G.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(H[a],function(b){return G[a][b]})}}),x.result=function(a,b){if(null==a)return void 0;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),M.call(this,c.apply(x,a))}})};var I=0;x.uniqueId=function(a){var b=++I+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var J=/(.)^/,K={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},L=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=new RegExp([(c.escape||J).source,(c.interpolate||J).source,(c.evaluate||J).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(L,function(a){return"\\"+K[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=new Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var M=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],M.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return M.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this),function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.inflection=b()}(this,function(){var a=["equipment","information","rice","money","species","series","fish","sheep","moose","deer","news"],b=[[new RegExp("(m)en$","gi")],[new RegExp("(pe)ople$","gi")],[new RegExp("(child)ren$","gi")],[new RegExp("([ti])a$","gi")],[new RegExp("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$","gi")],[new RegExp("(hive)s$","gi")],[new RegExp("(tive)s$","gi")],[new RegExp("(curve)s$","gi")],[new RegExp("([lr])ves$","gi")],[new RegExp("([^fo])ves$","gi")],[new RegExp("([^aeiouy]|qu)ies$","gi")],[new RegExp("(s)eries$","gi")],[new RegExp("(m)ovies$","gi")],[new RegExp("(x|ch|ss|sh)es$","gi")],[new RegExp("([m|l])ice$","gi")],[new RegExp("(bus)es$","gi")],[new RegExp("(o)es$","gi")],[new RegExp("(shoe)s$","gi")],[new RegExp("(cris|ax|test)es$","gi")],[new RegExp("(octop|vir)i$","gi")],[new RegExp("(alias|status)es$","gi")],[new RegExp("^(ox)en","gi")],[new RegExp("(vert|ind)ices$","gi")],[new RegExp("(matr)ices$","gi")],[new RegExp("(quiz)zes$","gi")],[new RegExp("(m)an$","gi"),"$1en"],[new RegExp("(pe)rson$","gi"),"$1ople"],[new RegExp("(child)$","gi"),"$1ren"],[new RegExp("^(ox)$","gi"),"$1en"],[new RegExp("(ax|test)is$","gi"),"$1es"],[new RegExp("(octop|vir)us$","gi"),"$1i"],[new RegExp("(alias|status)$","gi"),"$1es"],[new RegExp("(bu)s$","gi"),"$1ses"],[new RegExp("(buffal|tomat|potat)o$","gi"),"$1oes"],[new RegExp("([ti])um$","gi"),"$1a"],[new RegExp("sis$","gi"),"ses"],[new RegExp("(?:([^f])fe|([lr])f)$","gi"),"$1$2ves"],[new RegExp("(hive)$","gi"),"$1s"],[new RegExp("([^aeiouy]|qu)y$","gi"),"$1ies"],[new RegExp("(x|ch|ss|sh)$","gi"),"$1es"],[new RegExp("(matr|vert|ind)ix|ex$","gi"),"$1ices"],[new RegExp("([m|l])ouse$","gi"),"$1ice"],[new RegExp("(quiz)$","gi"),"$1zes"],[new RegExp("s$","gi"),"s"],[new RegExp("$","gi"),"s"]],c=[[new RegExp("(m)an$","gi")],[new RegExp("(pe)rson$","gi")],[new RegExp("(child)$","gi")],[new RegExp("^(ox)$","gi")],[new RegExp("(ax|test)is$","gi")],[new RegExp("(octop|vir)us$","gi")],[new RegExp("(alias|status)$","gi")],[new RegExp("(bu)s$","gi")],[new RegExp("(buffal|tomat|potat)o$","gi")],[new RegExp("([ti])um$","gi")],[new RegExp("sis$","gi")],[new RegExp("(?:([^f])fe|([lr])f)$","gi")],[new RegExp("(hive)$","gi")],[new RegExp("([^aeiouy]|qu)y$","gi")],[new RegExp("(x|ch|ss|sh)$","gi")],[new RegExp("(matr|vert|ind)ix|ex$","gi")],[new RegExp("([m|l])ouse$","gi")],[new RegExp("(quiz)$","gi")],[new RegExp("(m)en$","gi"),"$1an"],[new RegExp("(pe)ople$","gi"),"$1rson"],[new RegExp("(child)ren$","gi"),"$1"],[new RegExp("([ti])a$","gi"),"$1um"],[new RegExp("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$","gi"),"$1$2sis"],[new RegExp("(hive)s$","gi"),"$1"],[new RegExp("(tive)s$","gi"),"$1"],[new RegExp("(curve)s$","gi"),"$1"],[new RegExp("([lr])ves$","gi"),"$1f"],[new RegExp("([^fo])ves$","gi"),"$1fe"],[new RegExp("(m)ovies$","gi"),"$1ovie"],[new RegExp("([^aeiouy]|qu)ies$","gi"),"$1y"],[new RegExp("(s)eries$","gi"),"$1eries"],[new RegExp("(x|ch|ss|sh)es$","gi"),"$1"],[new RegExp("([m|l])ice$","gi"),"$1ouse"],[new RegExp("(bus)es$","gi"),"$1"],[new RegExp("(o)es$","gi"),"$1"],[new RegExp("(shoe)s$","gi"),"$1"],[new RegExp("(cris|ax|test)es$","gi"),"$1is"],[new RegExp("(octop|vir)i$","gi"),"$1us"],[new RegExp("(alias|status)es$","gi"),"$1"],[new RegExp("^(ox)en","gi"),"$1"],[new RegExp("(vert|ind)ices$","gi"),"$1ex"],[new RegExp("(matr)ices$","gi"),"$1ix"],[new RegExp("(quiz)zes$","gi"),"$1"],[new RegExp("ss$","gi"),"ss"],[new RegExp("s$","gi"),""]],d=["and","or","nor","a","an","the","so","but","to","of","at","by","from","into","on","onto","off","out","in","over","with","for"],e=new RegExp("(_ids|_id)$","g"),f=new RegExp("_","g"),g=new RegExp("[ _]","g"),h=new RegExp("([A-Z])","g"),i=new RegExp("^_"),j={_apply_rules:function(a,b,c,d){if(d)a=d;else{var e=j.indexOf(c,a.toLowerCase())>-1;if(!e)for(var f=0,g=b.length;g>f;f++)if(a.match(b[f][0])){void 0!==b[f][1]&&(a=a.replace(b[f][0],b[f][1]));break}}return a},indexOf:function(a,b,c,d){c||(c=-1);for(var e=-1,f=c,g=a.length;g>f;f++)if(a[f]===b||d&&d(a[f],b)){e=f;break}return e},pluralize:function(c,d){return j._apply_rules(c,b,a,d)},singularize:function(b,d){return j._apply_rules(b,c,a,d)},camelize:function(a,b){for(var c,d,e,f,g=a.split("/"),h=0,i=g.length;i>h;h++){for(c=g[h].split("_"),d=0,e=c.length;e>d;d++)0!==d&&(c[d]=c[d].toLowerCase()),f=c[d].charAt(0),f=b&&0===h&&0===d?f.toLowerCase():f.toUpperCase(),c[d]=f+c[d].substring(1);g[h]=c.join("")}return g.join("::")},underscore:function(a,b){if(b&&a===a.toUpperCase())return a;for(var c=a.split("::"),d=0,e=c.length;e>d;d++)c[d]=c[d].replace(h,"_$1"),c[d]=c[d].replace(i,"");return c.join("/").toLowerCase()},humanize:function(a,b){return a=a.toLowerCase(),a=a.replace(e,""),a=a.replace(f," "),b||(a=j.capitalize(a)),a},capitalize:function(a){return a=a.toLowerCase(),a.substring(0,1).toUpperCase()+a.substring(1)},dasherize:function(a){return a.replace(g,"-")},titleize:function(a){a=a.toLowerCase().replace(f," ");for(var b,c,e,g=a.split(" "),h=0,i=g.length;i>h;h++){for(b=g[h].split("-"),c=0,e=b.length;e>c;c++)j.indexOf(d,b[c].toLowerCase())<0&&(b[c]=j.capitalize(b[c]));g[h]=b.join("-")}return a=g.join(" "),a=a.substring(0,1).toUpperCase()+a.substring(1)},demodulize:function(a){var b=a.split("::");return b[b.length-1]},tableize:function(a){return a=j.underscore(a),a=j.pluralize(a)},classify:function(a){return a=j.camelize(a),a=j.singularize(a)},foreign_key:function(a,b){return a=j.demodulize(a),a=j.underscore(a)+(b?"":"_")+"id"},ordinalize:function(a){for(var b=a.split(" "),c=0,d=b.length;d>c;c++){var e=parseInt(b[c],10);if(!isNaN(e)){var f=b[c].substring(b[c].length-2),g=b[c].substring(b[c].length-1),h="th";"11"!=f&&"12"!=f&&"13"!=f&&("1"===g?h="st":"2"===g?h="nd":"3"===g&&(h="rd")),b[c]+=h}}return b.join(" ")},transform:function(a,b){for(var c=0,d=b.length;d>c;c++){var e=b[c];this.hasOwnProperty(e)&&(a=this[e](a))}return a}};return j.version="1.3.8",j}),function(a){if("function"==typeof bootstrap)bootstrap("promise",a);else if("object"==typeof exports)module.exports=a();else if("function"==typeof define&&define.amd)define(a);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=a}else Q=a()}(function(){"use strict";function a(a){return function(){return X.apply(a,arguments)}}function b(a){return a===Object(a)}function c(a){return"[object StopIteration]"===db(a)||a instanceof T}function d(a,b){if(Q&&b.stack&&"object"==typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(fb)){for(var c=[],d=b;d;d=d.source)d.stack&&c.unshift(d.stack);c.unshift(a.stack);var f=c.join("\n"+fb+"\n");a.stack=e(f)}}function e(a){for(var b=a.split("\n"),c=[],d=0;d=U&&kb>=d}function i(){if(Q)try{throw new Error}catch(a){var b=a.stack.split("\n"),c=b[0].indexOf("@")>0?b[1]:b[2],d=g(c);if(!d)return;return S=d[0],d[1]}}function j(a,b,c){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(b+" is deprecated, use "+c+" instead.",new Error("").stack),a.apply(a,arguments)}}function k(a){return r(a)?a:s(a)?D(a):C(a)}function l(){function a(a){b=a,f.source=a,Z(c,function(b,c){W(function(){a.promiseDispatch.apply(a,c)})},void 0),c=void 0,d=void 0}var b,c=[],d=[],e=ab(l.prototype),f=ab(o.prototype);if(f.promiseDispatch=function(a,e,f){var g=Y(arguments);c?(c.push(g),"when"===e&&f[1]&&d.push(f[1])):W(function(){b.promiseDispatch.apply(b,g)})},f.valueOf=j(function(){if(c)return f;var a=q(b);return r(a)&&(b=a),a},"valueOf","inspect"),f.inspect=function(){return b?b.inspect():{state:"pending"}},k.longStackSupport&&Q)try{throw new Error}catch(g){f.stack=g.stack.substring(g.stack.indexOf("\n")+1)}return e.promise=f,e.resolve=function(c){b||a(k(c))},e.fulfill=function(c){b||a(C(c))},e.reject=function(c){b||a(B(c))},e.notify=function(a){b||Z(d,function(b,c){W(function(){c(a)})},void 0)},e}function m(a){if("function"!=typeof a)throw new TypeError("resolver must be a function.");var b=l();try{a(b.resolve,b.reject,b.notify)}catch(c){b.reject(c)}return b.promise}function n(a){return m(function(b,c){for(var d=0,e=a.length;e>d;d++)k(a[d]).then(b,c)})}function o(a,b,c){void 0===b&&(b=function(a){return B(new Error("Promise does not support operation: "+a))}),void 0===c&&(c=function(){return{state:"unknown"}});var d=ab(o.prototype);if(d.promiseDispatch=function(c,e,f){var g;try{g=a[e]?a[e].apply(d,f):b.call(d,e,f)}catch(h){g=B(h)}c&&c(g)},d.inspect=c,c){var e=c();"rejected"===e.state&&(d.exception=e.reason),d.valueOf=j(function(){var a=c();return"pending"===a.state||"rejected"===a.state?d:a.value})}return d}function p(a,b,c,d){return k(a).then(b,c,d)}function q(a){if(r(a)){var b=a.inspect();if("fulfilled"===b.state)return b.value}return a}function r(a){return b(a)&&"function"==typeof a.promiseDispatch&&"function"==typeof a.inspect}function s(a){return b(a)&&"function"==typeof a.then}function t(a){return r(a)&&"pending"===a.inspect().state}function u(a){return!r(a)||"fulfilled"===a.inspect().state}function v(a){return r(a)&&"rejected"===a.inspect().state}function w(){ib||"undefined"==typeof window||window.Touch||!window.console||console.warn("[Q] Unhandled rejection reasons (should be empty):",gb),ib=!0}function x(){for(var a=0;a=d)throw new TypeError}for(;d>c;c++)c in this&&(b=a(b,this[c],c));return b}),$=a(Array.prototype.indexOf||function(a){for(var b=0;b2?Y(arguments,1):c)}},k.promise=m,k.passByCopy=function(a){return a},o.prototype.passByCopy=function(){return this},k.join=function(a,b){return k(a).join(b)},o.prototype.join=function(a){return k([this,a]).spread(function(a,b){if(a===b)return a;throw new Error("Can't join: not the same: "+a+" "+b)})},k.race=n,o.prototype.race=function(){return this.then(k.race)},k.makePromise=o,o.prototype.toString=function(){return"[object Promise]"},o.prototype.then=function(a,b,c){function e(b){try{return"function"==typeof a?a(b):b}catch(c){return B(c)}}function f(a){if("function"==typeof b){d(a,h);try{return b(a)}catch(c){return B(c)}}return B(a)}function g(a){return"function"==typeof c?c(a):a}var h=this,i=l(),j=!1;return W(function(){h.promiseDispatch(function(a){j||(j=!0,i.resolve(e(a)))},"when",[function(a){j||(j=!0,i.resolve(f(a)))}])}),h.promiseDispatch(void 0,"when",[void 0,function(a){var b,c=!1;try{b=g(a)}catch(d){if(c=!0,!k.onerror)throw d;k.onerror(d)}c||i.notify(b)}]),i.promise},k.when=p,o.prototype.thenResolve=function(a){return this.then(function(){return a})},k.thenResolve=function(a,b){return k(a).thenResolve(b)},o.prototype.thenReject=function(a){return this.then(function(){throw a})},k.thenReject=function(a,b){return k(a).thenReject(b)},k.nearer=q,k.isPromise=r,k.isPromiseAlike=s,k.isPending=t,o.prototype.isPending=function(){return"pending"===this.inspect().state},k.isFulfilled=u,o.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},k.isRejected=v,o.prototype.isRejected=function(){return"rejected"===this.inspect().state};var gb=[],hb=[],ib=!1,jb=!0;k.resetUnhandledRejections=y,k.getUnhandledReasons=function(){return gb.slice()},k.stopUnhandledRejectionTracking=function(){y(),"undefined"!=typeof process&&process.on&&process.removeListener("exit",x),jb=!1},y(),k.reject=B,k.fulfill=C,k.master=E,k.spread=F,o.prototype.spread=function(a,b){return this.all().then(function(b){return a.apply(void 0,b)},b)},k.async=G,k.spawn=H,k["return"]=I,k.promised=J,k.dispatch=K,o.prototype.dispatch=function(a,b){var c=this,d=l();return W(function(){c.promiseDispatch(d.resolve,a,b)}),d.promise},k.get=function(a,b){return k(a).dispatch("get",[b])},o.prototype.get=function(a){return this.dispatch("get",[a])},k.set=function(a,b,c){return k(a).dispatch("set",[b,c])},o.prototype.set=function(a,b){return this.dispatch("set",[a,b])},k.del=k["delete"]=function(a,b){return k(a).dispatch("delete",[b])},o.prototype.del=o.prototype["delete"]=function(a){return this.dispatch("delete",[a])},k.mapply=k.post=function(a,b,c){return k(a).dispatch("post",[b,c])},o.prototype.mapply=o.prototype.post=function(a,b){return this.dispatch("post",[a,b])},k.send=k.mcall=k.invoke=function(a,b){return k(a).dispatch("post",[b,Y(arguments,2)])},o.prototype.send=o.prototype.mcall=o.prototype.invoke=function(a){return this.dispatch("post",[a,Y(arguments,1)])},k.fapply=function(a,b){return k(a).dispatch("apply",[void 0,b])},o.prototype.fapply=function(a){return this.dispatch("apply",[void 0,a])},k["try"]=k.fcall=function(a){return k(a).dispatch("apply",[void 0,Y(arguments,1)])},o.prototype.fcall=function(){return this.dispatch("apply",[void 0,Y(arguments)])},k.fbind=function(a){var b=k(a),c=Y(arguments,1);return function(){return b.dispatch("apply",[this,c.concat(Y(arguments))])}},o.prototype.fbind=function(){var a=this,b=Y(arguments);return function(){return a.dispatch("apply",[this,b.concat(Y(arguments))])}},k.keys=function(a){return k(a).dispatch("keys",[])},o.prototype.keys=function(){return this.dispatch("keys",[])},k.all=L,o.prototype.all=function(){return L(this)},k.allResolved=j(M,"allResolved","allSettled"),o.prototype.allResolved=function(){return M(this)},k.allSettled=N,o.prototype.allSettled=function(){return this.then(function(a){return L(_(a,function(a){function b(){return a.inspect()}return a=k(a),a.then(b,b)}))})},k.fail=k["catch"]=function(a,b){return k(a).then(void 0,b)},o.prototype.fail=o.prototype["catch"]=function(a){return this.then(void 0,a)},k.progress=O,o.prototype.progress=function(a){return this.then(void 0,void 0,a) },k.fin=k["finally"]=function(a,b){return k(a)["finally"](b)},o.prototype.fin=o.prototype["finally"]=function(a){return a=k(a),this.then(function(b){return a.fcall().then(function(){return b})},function(b){return a.fcall().then(function(){throw b})})},k.done=function(a,b,c,d){return k(a).done(b,c,d)},o.prototype.done=function(a,b,c){var e=function(a){W(function(){if(d(a,f),!k.onerror)throw a;k.onerror(a)})},f=a||b||c?this.then(a,b,c):this;"object"==typeof process&&process&&process.domain&&(e=process.domain.bind(e)),f.then(void 0,e)},k.timeout=function(a,b,c){return k(a).timeout(b,c)},o.prototype.timeout=function(a,b){var c=l(),d=setTimeout(function(){c.reject(new Error(b||"Timed out after "+a+" ms"))},a);return this.then(function(a){clearTimeout(d),c.resolve(a)},function(a){clearTimeout(d),c.reject(a)},c.notify),c.promise},k.delay=function(a,b){return void 0===b&&(b=a,a=void 0),k(a).delay(b)},o.prototype.delay=function(a){return this.then(function(b){var c=l();return setTimeout(function(){c.resolve(b)},a),c.promise})},k.nfapply=function(a,b){return k(a).nfapply(b)},o.prototype.nfapply=function(a){var b=l(),c=Y(a);return c.push(b.makeNodeResolver()),this.fapply(c).fail(b.reject),b.promise},k.nfcall=function(a){var b=Y(arguments,1);return k(a).nfapply(b)},o.prototype.nfcall=function(){var a=Y(arguments),b=l();return a.push(b.makeNodeResolver()),this.fapply(a).fail(b.reject),b.promise},k.nfbind=k.denodeify=function(a){var b=Y(arguments,1);return function(){var c=b.concat(Y(arguments)),d=l();return c.push(d.makeNodeResolver()),k(a).fapply(c).fail(d.reject),d.promise}},o.prototype.nfbind=o.prototype.denodeify=function(){var a=Y(arguments);return a.unshift(this),k.denodeify.apply(void 0,a)},k.nbind=function(a,b){var c=Y(arguments,2);return function(){function d(){return a.apply(b,arguments)}var e=c.concat(Y(arguments)),f=l();return e.push(f.makeNodeResolver()),k(d).fapply(e).fail(f.reject),f.promise}},o.prototype.nbind=function(){var a=Y(arguments,0);return a.unshift(this),k.nbind.apply(void 0,a)},k.nmapply=k.npost=function(a,b,c){return k(a).npost(b,c)},o.prototype.nmapply=o.prototype.npost=function(a,b){var c=Y(b||[]),d=l();return c.push(d.makeNodeResolver()),this.dispatch("post",[a,c]).fail(d.reject),d.promise},k.nsend=k.nmcall=k.ninvoke=function(a,b){var c=Y(arguments,2),d=l();return c.push(d.makeNodeResolver()),k(a).dispatch("post",[b,c]).fail(d.reject),d.promise},o.prototype.nsend=o.prototype.nmcall=o.prototype.ninvoke=function(a){var b=Y(arguments,1),c=l();return b.push(c.makeNodeResolver()),this.dispatch("post",[a,b]).fail(c.reject),c.promise},k.nodeify=P,o.prototype.nodeify=function(a){return a?void this.then(function(b){W(function(){a(null,b)})},function(b){W(function(){a(b)})}):this};var kb=i();return k}),function(a,b){function c(a){var b=a.length,c=fb.type(a);return fb.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||"function"!==c&&(0===b||"number"==typeof b&&b>0&&b-1 in a)}function d(a){var b=ob[a]={};return fb.each(a.match(hb)||[],function(a,c){b[c]=!0}),b}function e(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=fb.expando+Math.random()}function f(a,c,d){var e;if(d===b&&1===a.nodeType)if(e="data-"+c.replace(sb,"-$1").toLowerCase(),d=a.getAttribute(e),"string"==typeof d){try{d="true"===d?!0:"false"===d?!1:"null"===d?null:+d+""===d?+d:rb.test(d)?JSON.parse(d):d}catch(f){}pb.set(a,c,d)}else d=b;return d}function g(){return!0}function h(){return!1}function i(){try{return T.activeElement}catch(a){}}function j(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function k(a,b,c){if(fb.isFunction(b))return fb.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return fb.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(Cb.test(b))return fb.filter(b,a,c);b=fb.filter(b,a)}return fb.grep(a,function(a){return bb.call(b,a)>=0!==c})}function l(a,b){return fb.nodeName(a,"table")&&fb.nodeName(1===b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function m(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function n(a){var b=Nb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function o(a,b){for(var c=a.length,d=0;c>d;d++)qb.set(a[d],"globalEval",!b||qb.get(b[d],"globalEval"))}function p(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(qb.hasData(a)&&(f=qb.access(a),g=qb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)fb.event.add(b,e,j[e][c])}pb.hasData(a)&&(h=pb.access(a),i=fb.extend({},h),pb.set(b,i))}}function q(a,c){var d=a.getElementsByTagName?a.getElementsByTagName(c||"*"):a.querySelectorAll?a.querySelectorAll(c||"*"):[];return c===b||c&&fb.nodeName(a,c)?fb.merge([a],d):d}function r(a,b){var c=b.nodeName.toLowerCase();"input"===c&&Kb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function s(a,b){if(b in a)return b;for(var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=_b.length;e--;)if(b=_b[e]+c,b in a)return b;return d}function t(a,b){return a=b||a,"none"===fb.css(a,"display")||!fb.contains(a.ownerDocument,a)}function u(b){return a.getComputedStyle(b,null)}function v(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=qb.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&t(d)&&(f[g]=qb.access(d,"olddisplay",z(d.nodeName)))):f[g]||(e=t(d),(c&&"none"!==c||!e)&&qb.set(d,"olddisplay",e?c:fb.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}function w(a,b,c){var d=Ub.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function x(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=fb.css(a,c+$b[f],!0,e)),d?("content"===c&&(g-=fb.css(a,"padding"+$b[f],!0,e)),"margin"!==c&&(g-=fb.css(a,"border"+$b[f]+"Width",!0,e))):(g+=fb.css(a,"padding"+$b[f],!0,e),"padding"!==c&&(g+=fb.css(a,"border"+$b[f]+"Width",!0,e)));return g}function y(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=u(a),g=fb.support.boxSizing&&"border-box"===fb.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=Qb(a,b,f),(0>e||null==e)&&(e=a.style[b]),Vb.test(e))return e;d=g&&(fb.support.boxSizingReliable||e===a.style[b]),e=parseFloat(e)||0}return e+x(a,b,c||(g?"border":"content"),d,f)+"px"}function z(a){var b=T,c=Xb[a];return c||(c=A(a,b),"none"!==c&&c||(Rb=(Rb||fb("