Module: Motr::Mods::Cargo

Extended by:
Motr::Modding
Defined in:
lib/motr/mods/cargo.rb

Overview

Cargo is the base mod for implementing content like behavior on a model. A model with “cargo” represents the core post/page/body object in which content is created/published. Cargo contains multiple “contexts” which define the fields/attributes that ultimately merge to create the final content to be delivered.

A context defines a “field” that belongs within a cargo object. Each “package” can contain one or many contexts, which when combined, in the user-defined order, make up the full body of content to be delivered.

For example, given a “Post” model, modded_with cargo, that post may have a “heading” context, and a “body” context. When combined into final, deliverable content, the result is a heading (h1, h2, h3 etc) and a body. Taking a blog as an example, this allows each piece of a post to be defined as individual contexts, giving developers full control over output and format… and relying less on the implementations of “wysiwyg” editors. (to be fair… it isn’t the editor’s fault).

When using the provided controllers, this also allows each individual aspect of a page to be edited as a standalone item.

Applying the cargo mod automatically creates the following fields

title:String
post_date:Time
published:Boolean
uid:Integer => Mongoid models only... this creates an auto-incrementing sql style id for each post

Applying a context automatically defines the following fields

name:String => The name of the context (ie "heading", "body"). This is optional and is really only for display
body:String => The actual body (content) of the context (ie the heading title or html body copy)
meta:Hash   => Allows storage of various metadata 
type:String => STI functionality. When creating different context types for an object, inheritance should be used. (this really only applies to ActiveRecord... as Mongoid handles this automatically)

Provide an :as option to define this model as a context. By default calling modded_with :cargo defines a “package” or “post” object.

Using :as with :context defines the model as a context. Defining a context requires the :for option

Pass a :for option when creating a context. The :for option is passed representing the model/models that this context is for.

These models should be modded_with :cargo