1 define(['libs/jquery', 'libs/underscore', 'fnpjs/logging/logging'], function($, _, logging) {
5 var Runner = function(app, modules) {
7 function getModuleInstance(moduleName) {
8 var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || modules[moduleName](new Sandbox(moduleName)));
12 var bootstrappedData = {},
18 _.each(_.keys(modules || {}), function(moduleName) {
19 if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
20 eventListeners.push(moduleName);
26 var Sandbox = function(moduleName) {
30 this.getBootstrappedData = function() {
31 return bootstrappedData[moduleName];
34 this.getTemplate = function(templateName) {
35 return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());
38 this.publish = function(eventName) {
39 var eventArgs = Array.prototype.slice.call(arguments, 1);
40 _.each(eventListeners, function(listenerModuleName) {
41 var listener = moduleInstances[listenerModuleName];
43 listener.handleEvent(moduleName, eventName, eventArgs);
48 var permissions = app.permissions[moduleName];
50 this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {
51 return getModuleInstance(requestedModuleName);
54 this.getDOM = _.contains(permissions, 'getDOM') ? function() {
55 return $(config.rootSelector);
58 this.getPlugins = function() {
62 this.getConfig = function() {
68 this.setBootstrappedData = function(moduleName, data) {
69 bootstrappedData[moduleName] = data;
72 this.registerPlugin = function(plugin) {
76 this.start = function(_config) {
83 logging.setConfig(config.logging);
86 app.initModules.forEach(function(moduleName) {
87 getModuleInstance(moduleName).start();