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

Commit

Permalink
Housekeeping. Grunt build fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hamilton committed Sep 6, 2012
1 parent b27b456 commit 0f97657
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 93 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
@@ -1,10 +1,4 @@
language: node_js
node_js:
- 0.8
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- npm install connect
- sudo node test/travis/server.js &
- sleep 5
script: phantomjs test/travis/run-qunit.js 'http://localhost:80/index.html'
script: grunt
3 changes: 1 addition & 2 deletions dist/applitude.js
Expand Up @@ -10,7 +10,6 @@

/*global jQuery, EventEmitter2, odotjs, window, setTimeout,
console, exports, navigator */

(function (root, $, o, events) {
'use strict';
var namespace = 'applitude',
Expand Down Expand Up @@ -193,4 +192,4 @@ console, exports, navigator */
odotjs,
new EventEmitter2({
wildcard: true
})));
})));
42 changes: 42 additions & 0 deletions grunt.js
@@ -0,0 +1,42 @@
/*global module*/
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
all: ['./grunt.js', './src/**/*.js', './test/test.js']
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
nonew: true,
noarg: true,
sub: true,
undef: true,
unused: true,
eqnull: true,
browser: true,
strict: true,
boss: false
}
},
concat: {
dist: {
src: ['src/applitude.js'],
dest: 'dist/applitude.js'
}
},
qunit: {
index: ['test/index.html']
},
watch: {
files: ['<config:lint.all>'],
tasks: ['lint', 'concat,', 'qunit']
}
});
grunt.registerTask('default', 'lint concat qunit');
};
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -24,16 +24,17 @@
"test": "./test"
},
"dependencies": {
"grunt": "~0.3.x",
"eventemitter2": "~0.4.x",
"odotjs": "~0.2.x",
"fs-extra": "~0.1.x"
},
"devDependencies": {
"grunt": "~0.3.x",
"tap": "~0.2.4"
},
"scripts": {
"postinstall": "node ./scripts/install.js"
"postinstall": "node ./scripts/install.js",
"test": "grunt"
},
"engines": {
"node": "~0.8.x",
Expand Down
195 changes: 195 additions & 0 deletions src/applitude.js
@@ -0,0 +1,195 @@
/**
* Applitude - Application namespacing and module management.
*
* Depends on jQuery, EventEmitter2, and odotjs
*
* Copyright (c) Eric Elliott 2012
* MIT License
* http://opensource.org/licenses/MIT
*/

/*global jQuery, EventEmitter2, odotjs, window, setTimeout,
console, exports, navigator */
(function (root, $, o, events) {
'use strict';
var namespace = 'applitude',
debugLog = [],
loadErrors = {},

/**
* Deferred utilities
*/
deferred = $.Deferred,
when = $.when,
resolved = deferred().resolve().promise(),
rejected = deferred().reject().promise(),
app,
register,
stringToArray,
addMixins,
whenRenderReady = deferred(),
setModule;

setModule = function val(cursor, location, value) {
var tree = location.split('.'),
key = tree.shift(),
returnValue;

while (tree.length) {
if (cursor[key] !== undefined) {
cursor = cursor[key];
} else {
cursor = cursor[key] = {};
}
key = tree.shift();
}

if (cursor[key] === undefined) {
cursor[key] = value;
returnValue = true;
} else {
returnValue = false;
}
return returnValue;
};

stringToArray = function stringToArray(input, pattern) {
var result;
pattern = pattern || /\s*\,\s*/;

result = (typeof input !== 'string') ?
result = [] :
result = input.trim().split(pattern);

return result;
};

addMixins = function addMixins(module) {
var mixins = stringToArray(module.mixins),
backup = o.extend({}, module);
mixins.forEach(function (mixin) {
if (app[mixin]) {
o.extend(module, app[mixin]);
}
});
return o.extend(module, backup);
};

app = function applitudeFunction(appNs, environment, options) {
var whenPageLoaded = deferred(),
beforeRenderOption = (options && options.beforeRender) || [],
beforeRender = [whenPageLoaded].concat(beforeRenderOption),
tryRender;

whenRenderReady = when.apply(null, beforeRender);

tryRender = function tryRender(module) {
if (typeof module.render === 'function') {
whenRenderReady.then(module.render, module.render);
}
};

register = function register(ns, module) {
var whenLoaded,
newModule;

module.moduleNamespace = ns;

newModule = setModule(app, ns, module, function () {
app.events.trigger('module_added' + app.appNamespace, ns);
});

if (newModule) {

if (module.mixins) {
addMixins(module);
}

// If load exists, try to load
if (typeof module.load === 'function') {
try {
// If a promise is returned, wait for load to finish.
whenLoaded = module.load();
if (whenLoaded && whenLoaded.done) {
whenLoaded.done(function () {
tryRender(module);
});
} else {
tryRender(module);
}
} catch (loadError) {
loadErrors[ns] = loadError;
app.log('Error loading module: ', ns, loadError);
}
} else if (!loadErrors[ns]) {
// if .render() exists, try to render
tryRender(module);
}

} else {
app.log('Error: Module already registered: ', ns);
}

return app;
};

$(function () {
whenPageLoaded.resolve();
});

// aliases
events.trigger = events.emit;

o.extend(app, {
register: register,
environment: environment,
appNamespace: appNs,
options: options
});

return app;
};

function on() {
app.events.on.apply(app.events, arguments);
}

function trigger() {
app.events.trigger.apply(app.events, arguments);
}

o.extend(app, {
deferred: deferred,
resolved: resolved,
rejected: rejected,
when: when,
o: o,
$: $,
get: $.get,
stringToArray: stringToArray,
isArray: $.isArray,
events: events,
on: on,
trigger: trigger,
debugLog: debugLog
});

app.log = function log() {
var debug = app.environment && app.environment.debug,
hasConsole = (window.console !== undefined) && console.log;
if (debug && hasConsole) {
console.log.apply(console, [].slice.call(arguments, 0));
} else {
debugLog.push(arguments);
}
};

root[namespace] = app;

}((typeof exports !== 'undefined') ?
exports : window,
jQuery,
odotjs,
new EventEmitter2({
wildcard: true
})));
1 change: 1 addition & 0 deletions test/test.js
@@ -1,5 +1,6 @@
/*global test, ok, applitude, equal, deepEqual, start, expect, stop, jQuery*/
(function (app, $) {
'use strict';
(function (app) {
var whenAppInitFinished = app.deferred();

Expand Down
72 changes: 0 additions & 72 deletions test/travis/run-qunit.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/travis/server.js

This file was deleted.

0 comments on commit 0f97657

Please sign in to comment.