All files / lib fruitmachine.js

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67                                        25x 25x 25x 25x                     25x                   36x 36x 35x   1x     25x 25x 25x 25x 25x 25x 25x 25x           25x    
/*jslint browser:true, node:true*/
 
/**
 * FruitMachine
 *
 * Renders layouts/modules from a basic layout definition.
 * If views require custom interactions devs can extend
 * the basic functionality.
 *
 * @version 0.3.3
 * @copyright The Financial Times Limited [All Rights Reserved]
 * @author Wilson Page <wilson.page@ft.com>
 */
 
'use strict';
 
/**
 * Module Dependencies
 */
 
var mod = require('./module');
var define = require('./define');
var utils = require('utils');
var events = require('evt');
 
/**
 * Creates a fruitmachine
 *
 * Options:
 *
 *  - `Model` A model constructor to use (must have `.toJSON()`)
 *
 * @param {Object} options
 */
module.exports = function(options) {
 
  /**
   * Shortcut method for
   * creating lazy views.
   *
   * @param  {Object} options
   * @return {Module}
   */
  function fm(options) {
    var Module = fm.modules[options.module];
    if (Module) {
      return new Module(options);
    }
    throw new Error("Unable to find module '" + options.module + "'");
  }
 
  fm.create = module.exports;
  fm.Model = options.Model;
  fm.Events = events;
  fm.Module = mod(fm);
  fm.define = define(fm);
  fm.util = utils;
  fm.modules = {};
  fm.config = {
    templateIterator: 'children',
    templateInstance: 'child'
  };
 
  // Mixin events and return
  return events(fm);
};