All files / test helpers.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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 12525x 25x   25x           25x                       25x   25x                   25x                   25x                   25x                   25x                           25x 73x 73x 73x 73x   73x         73x             25x 83x 83x 83x             25x 27x 27x     25x 5x     25x   25x 25x 25x 25x 25x 25x 25x 25x  
var Hogan = require('hogan.js');
var fruitmachine = require('../lib/');
 
var helpers = {};
 
/**
 * Templates
 */
 
var templates = helpers.templates = {
  'apple': Hogan.compile('{{{1}}}'),
  'layout': Hogan.compile('{{{1}}}{{{2}}}{{{3}}}'),
  'list': Hogan.compile('{{#children}}{{{child}}}{{/children}}'),
  'orange': Hogan.compile('{{text}}'),
  'pear': Hogan.compile('{{text}}')
};
 
/**
 * Module Definitions
 */
 
helpers.Views = {};
 
var Layout = helpers.Views.Layout = fruitmachine.define({
  name: 'layout',
  template: templates.layout,
 
  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
});
 
var Apple = helpers.Views.Apple = fruitmachine.define({
  name: 'apple',
  template: templates.apple,
 
  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
});
 
var List = helpers.Views.List = fruitmachine.define({
  name: 'list',
  template: templates.list,
 
  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
});
 
var Orange = helpers.Views.Orange = fruitmachine.define({
  name: 'orange',
  template: templates.orange,
 
  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
});
 
var Pear = helpers.Views.Pear = fruitmachine.define({
  name: 'pear',
  template: templates.pear,
 
  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
});
 
/**
 * Create View
 */
 
helpers.createView = function() {
  var layout = new Layout();
  var apple = new Apple({ slot: 1 });
  var orange = new Orange({ slot: 2 });
  var pear = new Pear({ slot: 3 });
 
  layout
    .add(apple)
    .add(orange)
    .add(pear);
 
  return this.view = layout;
};
 
/**
 * Destroy View
 */
 
helpers.destroyView = function(view) {
  var viewToDestroy = this.view || view;
  viewToDestroy.destroy();
  this.view = null;
};
 
/**
 * Sandbox
 */
 
helpers.createSandbox = function() {
  var el = document.createElement('div');
  return document.body.appendChild(el);
};
 
helpers.emptySandbox = function() {
  sandbox.innerHTML = '';
};
 
var sandbox = helpers.createSandbox();
 
global.fruitmachine = fruitmachine;
global.helpers = helpers;
global.sandbox = sandbox;
global.Layout = Layout;
global.Apple = Apple;
global.List = List;
global.Orange = Orange;
global.Pear = Pear;