UNPKG

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.

107 lines (92 loc) 2.4 kB
// Generated by CoffeeScript 2.5.1 // ===================================== // Requires // External var Collection, ElementsCollection, Model, typeChecker; typeChecker = require('typechecker'); // Local ({Collection, Model} = require('../base')); ElementsCollection = (function() { // ===================================== // Classes /** * Base class for the DocPad Elements Collection object * Extends the DocPad collection class * Used as the base collection class for specific collection of file types. * In particular metadata, scripts and styles. * @class ElementsCollection * @constructor * @extends Collection */ class ElementsCollection extends Collection { /** * Add an element to the collection. * Right now we just support strings. * @method add * @param {Array} values string array of values * @param {Object} opts */ add(values, opts) { var i, key, len, value; // Ensure array if (typeChecker.isArray(values)) { values = values.slice(); } else if (values) { values = [values]; } else { values = []; } // Convert string based array properties into html for (key = i = 0, len = values.length; i < len; key = ++i) { value = values[key]; if (typeChecker.isString(value)) { values[key] = new Model({ html: value }); } } // Call the super with our values super.add(values, opts); return this; } // Chain set() { super.set(...arguments); return this; } remove() { super.remove(...arguments); return this; } reset() { super.reset(...arguments); return this; } /** * Create a way to output our elements to HTML * @method toHTML * @return {String} */ toHTML() { var html; html = ''; this.forEach(function(item) { return html += item.get('html') || ''; }); return html; } // Join alias toHTML for b/c join() { return this.toHTML(); } }; /** * Base Model for all items in this collection * @property {Object} model */ ElementsCollection.prototype.model = Model; return ElementsCollection; }).call(this); // ===================================== // Export module.exports = ElementsCollection;