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.
81 lines (65 loc) • 1.63 kB
text/coffeescript
# =====================================
# Requires
# External
typeChecker = require('typechecker')
# Local
{Collection,Model} = require('../base')
# =====================================
# 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
###*
# Base Model for all items in this collection
# @property {Object} model
###
model: Model
###*
# 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) ->
# Ensure array
if typeChecker.isArray(values)
values = values.slice()
else if values
values = [values]
else
values = []
# Convert string based array properties into html
for value,key in values
if typeChecker.isString(value)
values[key] = new Model({html:value})
# Call the super with our values
super(values, opts)
# Chain
@
# Chain
set: -> super(arguments...); @
remove: -> super(arguments...); @
reset: -> super(arguments...); @
###*
# Create a way to output our elements to HTML
# @method toHTML
# @return {String}
###
toHTML: ->
html = ''
@forEach (item) ->
html += item.get('html') or ''
html
# Join alias toHTML for b/c
join: -> @toHTML()
# =====================================
# Export
module.exports = ElementsCollection