Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Core Calipso

cliftonc edited this page Jul 29, 2011 · 7 revisions

Calipso

The lib/calipso.js library is the engine of Calipso, it must be included in every module, and binds together all of the libraries, modules, helper classes, theming and is ultimately responsible for responding to a user request.

Calipso as Connect Middleware

To import the Calipso library as connect middleware:

  var calipso = require("calipso");
  app.use(calipso.calipsoRouter(app, app.set('config'), next);

The express object is passed through to enable it to be linked to the Calipso object, and hence be available (e.g. to access configuration via app.set('config') within any module).

Note - this can probably be refactored to make it look much less clunky :)

The Calipso Router is defined in more detail on this page: the Calipso Router Middleware.

Exports

The Calipso object exports the following:

Export Description
lib Common 3rd party libraries (avoids modules having to reimport these everywhere).
dynamicHelpers Helper functions (uninitialised) that can be used in views.
getDynamicHelpers Initialises helper functions for a specific request
mr Tracks running map reduce operations.
sessionCache Local cache for sessions (if required - not used currently)
data Used to hold simple core cached data (e.g. content types).
e Holder for events and event listeners.
theme The loaded theme object (created during bootstrap).
modules All loaded modules.
cache Theme / rendering cache library - not currently used.
date Date library
form Form library
table Table library
link Link library
menu Menu library
event Event library
utils General utils
calipsoRouter The middleware that responds to a request.

As all modules are expected to require the calipso library, all of these functions are typically available within any module e.g.

calipso.form.render(form,formValues,req,next); 

or

var myDate = calipso.date.parseDate(format,dateString,settings);

Imported Libraries

These are all core dependencies of Calipso, that are all available via calipso.lib:

fs: require('fs'),
path: require('path'),
express: require('express'),
step: require('step'),
sys: require('sys'),
mongoose: require('mongoose'),
url: require('url'),
ejs: require('ejs'),
pager: require('utils/pager'),
prettyDate: require('utils/prettyDate.js'),
crypto: require('utils/crypto.js'),
connect: require('connect'),
_:require('underscore')

For example:

calipso.lib.step();
var _ = calipso.lib._;

Return to Index