docpad
Version:
DocPad is a dynamic static site generator. Write your content as files, or import your content from other external sources. Render the content with plugins. And deploy your static or dynamic website to your favourite hosting provider.
173 lines (133 loc) • 3.98 kB
JavaScript
// Generated by CoffeeScript 2.5.1
// =====================================
// Requires
// External
/**
* Base class for the DocPad collection object
* Extends the backbone.js collection object
* http://backbonejs.org/#Collection
* @class Collection
* @constructor
* @extends queryEngine.Backbone.Collection
*/
/**
* Base class for the DocPad file and document model
* Extends the backbone.js model
* http://backbonejs.org/#Model
* @class Model
* @constructor
* @extends queryEngine.Backbone.Model
*/
/**
* Base class for the DocPad query collection object
* Extends the bevry QueryEngine object
* http://github.com/bevry/query-engine
* @class QueryCollection
* @constructor
* @extends queryEngine.QueryCollection
*/
var Collection, Events, Model, QueryCollection, emit, extendr, log, queryEngine,
hasProp = {}.hasOwnProperty,
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } };
extendr = require('extendr');
queryEngine = require('query-engine');
// =====================================
// Helpers
// Log a message
log = function(...args) {
args.unshift('log');
this.emit.apply(this, args);
return this;
};
emit = function(...args) {
return this.trigger.apply(this, args);
};
Events = (function() {
// =====================================
// Classes
// -------------------------------------
// Backbone
/**
* Base class for the DocPad Events object
* Extends the backbone.js events object
* http://backbonejs.org/#Events
* @class Events
* @constructor
* @extends queryEngine.Backbone.Events
*/
class Events {};
Events.prototype.log = log;
Events.prototype.emit = emit;
return Events;
}).call(this);
extendr.extend(Events.prototype, queryEngine.Backbone.Events);
Model = (function() {
class Model extends queryEngine.Backbone.Model {
// Set Defaults
setDefaults(attrs = {}, opts) {
var key, ref, set, value;
// Extract
set = {};
for (key in attrs) {
if (!hasProp.call(attrs, key)) continue;
value = attrs[key];
if (this.get(key) === ((ref = this.defaults) != null ? ref[key] : void 0)) {
set[key] = value;
}
}
// Forward
return this.set(set, opts);
}
};
Model.prototype.log = log;
Model.prototype.emit = emit;
return Model;
}).call(this);
Collection = (function() {
class Collection extends queryEngine.Backbone.Collection {
constructor() {
super(...arguments);
this.destroy = this.destroy.bind(this);
}
destroy() {
boundMethodCheck(this, Collection);
this.emit('destroy');
this.off().stopListening();
return this;
}
};
Collection.prototype.log = log;
Collection.prototype.emit = emit;
return Collection;
}).call(this);
Collection.prototype.model = Model;
Collection.prototype.collection = Collection;
QueryCollection = (function() {
class QueryCollection extends queryEngine.QueryCollection {
constructor() {
super(...arguments);
this.destroy = this.destroy.bind(this);
}
setParentCollection() {
var parentCollection;
super.setParentCollection(...arguments);
parentCollection = this.getParentCollection();
parentCollection.on('destroy', this.destroy);
return this;
}
destroy() {
boundMethodCheck(this, QueryCollection);
this.emit('destroy');
this.off().stopListening();
return this;
}
};
QueryCollection.prototype.log = log;
QueryCollection.prototype.emit = emit;
return QueryCollection;
}).call(this);
QueryCollection.prototype.model = Model;
QueryCollection.prototype.collection = QueryCollection;
// =====================================
// Export our base models
module.exports = {Events, Model, Collection, QueryCollection};