Permalink
Browse files

Merge pull request #1 from drewfish/lite-unit

fix unit tests (and delint)
  • Loading branch information...
2 parents 4ca2536 + 7f7c2a8 commit 3811d7e0c22d3e0557a80989d3adc8f94edbc041 @caridy caridy committed Oct 9, 2012
View
714 lib/app/addons/ac/output-adapter.common.js
@@ -16,363 +16,363 @@ YUI.add('mojito-output-adapter-addon', function(Y, NAME) {
return;
- var CHARSET = 'charset=utf-8',
- // the functions this core addon is going to attach to the
- // ActionContext
- flush,
- done,
- error,
-
- // serializer container
- serializer,
- // private functions
- serialize_xml,
- serialize_json,
- sanitizeConfigCopy,
- sanitizeChildren,
- attachChildViewIdsToMetaChildren,
- CACHE = { renderers: { } };
-
- /* see action-context.common.js for docs */
- flush = function(data, meta) {
- // NOTE: 'this' is the ActionContext instance
- return this.done(data, meta, true);
- };
-
-
- /* see action-context.common.js for docs */
- done = function(data, meta, more) {
-
- // NOTE: 'this' is the ActionContext instance
- var callbackFunc = more ? 'flush' : 'done',
- instance = this.command.instance,
- config = instance.config || {},
- context = this.command.context || {},
- adapter = this._adapter,
- action = this.command.action,
- mojitView,
- renderer = null,
- contentType,
- contentPath,
- appConfig = this.app.config,
- viewEngineOptions,
- perf = Y.mojito.perf.timeline('mojito', 'ac.done',
- 'time to execute ac.done process', this.command);
-
- if (Y.Lang.isString(meta)) {
- // If the meta string is a serializer set it
- if (serializer[meta]) {
- meta = {
- serialize: meta
- };
- } else {// Otherwise we think it is a template name
- meta = {
- view: {name: meta}
- };
- }
- }
-
- meta = meta || {};
- meta.assets = meta.assets || {};
- meta.assets.bottom = meta.assets.bottom || {};
- meta.assets.bottom.js = meta.assets.bottom.js || [];
- meta.http = meta.http || {};
- meta.http.code = meta.http.code || 200;
- meta.http.headers = meta.http.headers || {};
- meta.view = meta.view || {};
- viewEngineOptions = appConfig.viewEngine || {};
-
- // Cache all tempates by default
- meta.view.cacheTemplates = true;
-
- if (appConfig.cacheViewTemplates) {
- meta.view.cacheTemplates = appConfig.cacheViewTemplates || false;
- }
-
- // Check to see we need to serialize the data
- if (meta.serialize && serializer[meta.serialize]) {
- // Warning: this metod can change the "meta" object
- data = serializer[meta.serialize].apply(this, [data, meta]);
- // Once we are done remove the "serialize" option so others don't
- // use it by mistake
- delete meta.serialize;
- }
-
- // We want to know the view name, id, and binder used later so make sure
- // "meta" is up-to-date
- meta.view.name = meta.view.name || action;
- // TODO: Use a different binder
- meta.view.binder = meta.view.binder || meta.view.name;
- mojitView = instance.views[meta.view.name];
- if (!meta.view.id) {
- meta.view.id = Y.guid();
- //DEBUGGING: meta.view.id += '-viewId-' +
- // this.command.instance.type + '-' + this.command.action;
- }
-
- // If we are given "meta.view['content-path']" use it over what we got
- // from "instance.views"
- if (mojitView && meta.view['content-path']) {
- mojitView['content-path'] = meta.view['content-path'];
- }
-
- // If we are given "meta.view['engine']" use it over what we got from
- // "instance.views"
- if (mojitView && meta.view.engine) {
- mojitView.engine = meta.view.engine;
- }
-
- meta.assets = Y.mojito.util.metaMerge(meta.assets, config.assets || {});
- // Here we ask each "thing" attached to the AC if it wants to add view
- // "meta"
- Y.Object.each(this, function(item) {
- if (item && Y.Lang.isFunction(item.mergeMetaInto)) {
- item.mergeMetaInto(meta);
- }
- });
-
- contentType = meta.http.headers['content-type'];
-
- attachChildViewIdsToMetaChildren(meta.children, meta.binders);
-
- if (!meta.binders) {
- meta.binders = {};
- }
-
- // Don't clobber an existing meta.binders[meta.view.id] entry
- if (!meta.binders[meta.view.id]) {
- meta.binders[meta.view.id] = {
- base: instance.base,
- action: action,
- config: sanitizeConfigCopy(instance.config),
- type: instance.type,
- viewId: meta.view.id,
- guid: instance.instanceId, // DEPRECATED, use instanceId
- instanceId: instance.instanceId,
- // We don't use the actual config's children object, because
- // that might not have been what was actually dispatched. We get
- // the actual children config that was dispatched through the
- // meta object.
- children: sanitizeChildren(meta.children)
- };
- }
-
- /*
- * Here we provide an easy way to return a string
- * data == 'a string of chars'
- */
- if (Y.Lang.isString(data)) {
- // if the user didn't provided a content type, we'll make it plain
- // text
- if (!contentType) {
- meta.http.headers['content-type'] = ['text/plain; ' + CHARSET];
- }
- //Y.log('pushing to native adapter', 'info', NAME);
- adapter[callbackFunc](data, meta);
-
- perf.done(); // closing the 'ac.done' timeline
-
- return;
- }
-
- // there may not be a view if this is running on the client
- if (mojitView) {
-
- data = data || {}; // default null data to empty view template
-
- // Get the YUI Module name of the Binder if we can.
- if (meta.binders[meta.view.id]) {
- meta.binders[meta.view.id].name = mojitView['binder-module'];
- meta.binders[meta.view.id].needs =
- mojitView['binder-yui-sorted'];
- }
-
- if (!contentType) {
- meta.http.headers['content-type'] = ['text/html; ' + CHARSET];
- }
-
- data.mojit_guid = instance.instanceId;
- data.mojit_view_id = meta.view.id;
- data.mojit_assets = this.command.instance.assetsRoot;
-
- // Use engine to compile template view
- // Y.log('Rendering "' + meta.view.name + '" view for "' +
- // (instance.id || '@' + instance.type) + '"', 'info', NAME);
-
- contentPath = mojitView['content-path'];
- // this is mainly used by html5app
- if (appConfig.pathToRoot) {
- contentPath = appConfig.pathToRoot + contentPath;
- }
-
- // optimize for server only
- if (typeof context.runtime !== undefined && 'server' === context.runtime) {
- renderer = CACHE.renderers[mojitView.engine];
- if (!renderer) {
- // viewEngineOptions are app level
- CACHE.renderers[mojitView.engine] = renderer =
- new (Y.mojito.addons.viewEngines[mojitView.engine])('', viewEngineOptions);
- }
- renderer.viewId = meta.view.id;
- renderer.render(data, instance.type, contentPath, adapter, meta, more);
- } else {
- renderer = new Y.mojito.ViewRenderer(
- mojitView.engine,
- meta.view.id,
- viewEngineOptions
- );
- renderer.render(data, instance.type, contentPath, adapter, meta, more);
- }
-
- } else {
-
- if (Y.Lang.isObject(data)) {
- throw new Error("Missing view template: '" + meta.view.name +
- "'");
- }
- adapter[callbackFunc](data, meta);
- }
-
- perf.done(); // closing the 'ac.done' timeline
-
- Y.mojito.perf.mark('mojito', 'action:stop', 'after the action', this.command);
- };
-
-
- /* see action-context.common.js for docs */
- error = function(err) {
- // NOTE: 'this' is the ActionContext instance
- this._adapter.error(err);
- };
-
-
- sanitizeConfigCopy = function(cfg) {
- var copy;
- if (!Y.Lang.isObject(cfg)) {
- return cfg;
- }
- copy = Y.mojito.util.copy(cfg);
- copy.children = sanitizeChildren(copy.children);
- return copy;
- };
-
-
- sanitizeChildren = function(children) {
- if (!Y.Lang.isObject(children)) {
- return children;
- }
- Y.Object.each(children, function(v, k) {
- // We don't want child params to be included within a mojit's
- // configuration, because it can leak implemenation details out to
- // other execution environments. For example, the client runtime
- // does not need to have the parameters of the mojits that were used
- // to construct the initial client DOM.
- delete children[k].params;
- });
- return children;
- };
-
-
- attachChildViewIdsToMetaChildren = function(children, binders) {
- if (!children) {
- return;
- }
- Y.Object.each(binders, function(binderData, viewId) {
- Y.Object.each(children, function(childData) {
- if (binderData.instanceId === childData.instanceId) {
- childData.viewId = viewId;
- }
- });
- });
- };
-
-
- /*
- * @method serialize_json
- * @private
- * @param {object} data
- * @param {object} meta
- * @return {string}
- */
- serialize_json = function(data, meta) {
- meta.http.headers['content-type'] = ['application/json; ' + CHARSET];
-
- try {
- return Y.JSON.stringify(data);
- } catch (err) {
- throw new Error('Expected JSON data, but there was a parse error' +
- ' on the string: \"' + data);
- }
-
- };
-
-
- /*
- * @method serialize_xml
- * @private
- * @param {object} data
- * @param {object} meta
- * @return {string}
- */
- serialize_xml = function(data, meta) {
- // A dirty XML function I found on the interwebs
- function simpleXml(js, wraptag) {
- if (js instanceof Object) {
- return simpleXml(Y.Object.keys(js).map(function(key) {
- return simpleXml(js[key], key);
- }).join('\n'), wraptag);
- }
-
- return ((wraptag) ? '<' + wraptag + '>' : '') + js +
- ((wraptag) ? '</' + wraptag + '>' : ''
- );
- }
-
- meta.http.headers['content-type'] = ['application/xml; ' + CHARSET];
- if (Y.Lang.isObject) {
- try {
- return simpleXml(data, 'xml');
- } catch (err) {
- throw new Error('Expected XML data, but there was a parse' +
- ' error on the string: \"' + err.message);
- }
- }
-
- return '';
- };
-
-
- serializer = {
- json: serialize_json,
- xml: serialize_xml
- };
-
-
- /**
- * <strong>Access point:</strong> <em>ac.*</em>
- * The main API point for developers in a Controller. This addon provides
- * the core functions
- * of the ActionContext: <em>flush</em>, <em>done</em>, and <em>error</em>.
- * @class OutputAdapter.common
- * @private
- */
- function Addon(command, adapter, ac) {
- /*
- * This plugin doesn't act the same way as the others. It attaches its
- * functions directly onto the ActionContext. Each functions is assumed
- * that 'this' will be the actual instance of ActionContext, not the
- * object this constructor is creating.
- */
- ac.flush = flush;
- ac.done = done;
- ac.error = error;
- }
-
- Addon.prototype = {
- namespace: 'core'
- };
-
- Y.namespace('mojito.addons.ac').core = Addon;
+// var CHARSET = 'charset=utf-8',
+// // the functions this core addon is going to attach to the
+// // ActionContext
+// flush,
+// done,
+// error,
+
+// // serializer container
+// serializer,
+// // private functions
+// serialize_xml,
+// serialize_json,
+// sanitizeConfigCopy,
+// sanitizeChildren,
+// attachChildViewIdsToMetaChildren,
+// CACHE = { renderers: { } };
+
+// /* see action-context.common.js for docs */
+// flush = function(data, meta) {
+// // NOTE: 'this' is the ActionContext instance
+// return this.done(data, meta, true);
+// };
+
+
+// /* see action-context.common.js for docs */
+// done = function(data, meta, more) {
+
+// // NOTE: 'this' is the ActionContext instance
+// var callbackFunc = more ? 'flush' : 'done',
+// instance = this.command.instance,
+// config = instance.config || {},
+// context = this.command.context || {},
+// adapter = this._adapter,
+// action = this.command.action,
+// mojitView,
+// renderer = null,
+// contentType,
+// contentPath,
+// appConfig = this.app.config,
+// viewEngineOptions,
+// perf = Y.mojito.perf.timeline('mojito', 'ac.done',
+// 'time to execute ac.done process', this.command);
+
+// if (Y.Lang.isString(meta)) {
+// // If the meta string is a serializer set it
+// if (serializer[meta]) {
+// meta = {
+// serialize: meta
+// };
+// } else {// Otherwise we think it is a template name
+// meta = {
+// view: {name: meta}
+// };
+// }
+// }
+
+// meta = meta || {};
+// meta.assets = meta.assets || {};
+// meta.assets.bottom = meta.assets.bottom || {};
+// meta.assets.bottom.js = meta.assets.bottom.js || [];
+// meta.http = meta.http || {};
+// meta.http.code = meta.http.code || 200;
+// meta.http.headers = meta.http.headers || {};
+// meta.view = meta.view || {};
+// viewEngineOptions = appConfig.viewEngine || {};
+
+// // Cache all tempates by default
+// meta.view.cacheTemplates = true;
+
+// if (appConfig.cacheViewTemplates) {
+// meta.view.cacheTemplates = appConfig.cacheViewTemplates || false;
+// }
+
+// // Check to see we need to serialize the data
+// if (meta.serialize && serializer[meta.serialize]) {
+// // Warning: this metod can change the "meta" object
+// data = serializer[meta.serialize].apply(this, [data, meta]);
+// // Once we are done remove the "serialize" option so others don't
+// // use it by mistake
+// delete meta.serialize;
+// }
+
+// // We want to know the view name, id, and binder used later so make sure
+// // "meta" is up-to-date
+// meta.view.name = meta.view.name || action;
+// // TODO: Use a different binder
+// meta.view.binder = meta.view.binder || meta.view.name;
+// mojitView = instance.views[meta.view.name];
+// if (!meta.view.id) {
+// meta.view.id = Y.guid();
+// //DEBUGGING: meta.view.id += '-viewId-' +
+// // this.command.instance.type + '-' + this.command.action;
+// }
+
+// // If we are given "meta.view['content-path']" use it over what we got
+// // from "instance.views"
+// if (mojitView && meta.view['content-path']) {
+// mojitView['content-path'] = meta.view['content-path'];
+// }
+
+// // If we are given "meta.view['engine']" use it over what we got from
+// // "instance.views"
+// if (mojitView && meta.view.engine) {
+// mojitView.engine = meta.view.engine;
+// }
+
+// meta.assets = Y.mojito.util.metaMerge(meta.assets, config.assets || {});
+// // Here we ask each "thing" attached to the AC if it wants to add view
+// // "meta"
+// Y.Object.each(this, function(item) {
+// if (item && Y.Lang.isFunction(item.mergeMetaInto)) {
+// item.mergeMetaInto(meta);
+// }
+// });
+
+// contentType = meta.http.headers['content-type'];
+
+// attachChildViewIdsToMetaChildren(meta.children, meta.binders);
+
+// if (!meta.binders) {
+// meta.binders = {};
+// }
+
+// // Don't clobber an existing meta.binders[meta.view.id] entry
+// if (!meta.binders[meta.view.id]) {
+// meta.binders[meta.view.id] = {
+// base: instance.base,
+// action: action,
+// config: sanitizeConfigCopy(instance.config),
+// type: instance.type,
+// viewId: meta.view.id,
+// guid: instance.instanceId, // DEPRECATED, use instanceId
+// instanceId: instance.instanceId,
+// // We don't use the actual config's children object, because
+// // that might not have been what was actually dispatched. We get
+// // the actual children config that was dispatched through the
+// // meta object.
+// children: sanitizeChildren(meta.children)
+// };
+// }
+
+// /*
+// * Here we provide an easy way to return a string
+// * data == 'a string of chars'
+// */
+// if (Y.Lang.isString(data)) {
+// // if the user didn't provided a content type, we'll make it plain
+// // text
+// if (!contentType) {
+// meta.http.headers['content-type'] = ['text/plain; ' + CHARSET];
+// }
+// //Y.log('pushing to native adapter', 'info', NAME);
+// adapter[callbackFunc](data, meta);
+
+// perf.done(); // closing the 'ac.done' timeline
+
+// return;
+// }
+
+// // there may not be a view if this is running on the client
+// if (mojitView) {
+
+// data = data || {}; // default null data to empty view template
+
+// // Get the YUI Module name of the Binder if we can.
+// if (meta.binders[meta.view.id]) {
+// meta.binders[meta.view.id].name = mojitView['binder-module'];
+// meta.binders[meta.view.id].needs =
+// mojitView['binder-yui-sorted'];
+// }
+
+// if (!contentType) {
+// meta.http.headers['content-type'] = ['text/html; ' + CHARSET];
+// }
+
+// data.mojit_guid = instance.instanceId;
+// data.mojit_view_id = meta.view.id;
+// data.mojit_assets = this.command.instance.assetsRoot;
+
+// // Use engine to compile template view
+// // Y.log('Rendering "' + meta.view.name + '" view for "' +
+// // (instance.id || '@' + instance.type) + '"', 'info', NAME);
+
+// contentPath = mojitView['content-path'];
+// // this is mainly used by html5app
+// if (appConfig.pathToRoot) {
+// contentPath = appConfig.pathToRoot + contentPath;
+// }
+
+// // optimize for server only
+// if (typeof context.runtime !== undefined && 'server' === context.runtime) {
+// renderer = CACHE.renderers[mojitView.engine];
+// if (!renderer) {
+// // viewEngineOptions are app level
+// CACHE.renderers[mojitView.engine] = renderer =
+// new (Y.mojito.addons.viewEngines[mojitView.engine])('', viewEngineOptions);
+// }
+// renderer.viewId = meta.view.id;
+// renderer.render(data, instance.type, contentPath, adapter, meta, more);
+// } else {
+// renderer = new Y.mojito.ViewRenderer(
+// mojitView.engine,
+// meta.view.id,
+// viewEngineOptions
+// );
+// renderer.render(data, instance.type, contentPath, adapter, meta, more);
+// }
+
+// } else {
+
+// if (Y.Lang.isObject(data)) {
+// throw new Error("Missing view template: '" + meta.view.name +
+// "'");
+// }
+// adapter[callbackFunc](data, meta);
+// }
+
+// perf.done(); // closing the 'ac.done' timeline
+
+// Y.mojito.perf.mark('mojito', 'action:stop', 'after the action', this.command);
+// };
+
+
+// /* see action-context.common.js for docs */
+// error = function(err) {
+// // NOTE: 'this' is the ActionContext instance
+// this._adapter.error(err);
+// };
+
+
+// sanitizeConfigCopy = function(cfg) {
+// var copy;
+// if (!Y.Lang.isObject(cfg)) {
+// return cfg;
+// }
+// copy = Y.mojito.util.copy(cfg);
+// copy.children = sanitizeChildren(copy.children);
+// return copy;
+// };
+
+
+// sanitizeChildren = function(children) {
+// if (!Y.Lang.isObject(children)) {
+// return children;
+// }
+// Y.Object.each(children, function(v, k) {
+// // We don't want child params to be included within a mojit's
+// // configuration, because it can leak implemenation details out to
+// // other execution environments. For example, the client runtime
+// // does not need to have the parameters of the mojits that were used
+// // to construct the initial client DOM.
+// delete children[k].params;
+// });
+// return children;
+// };
+
+
+// attachChildViewIdsToMetaChildren = function(children, binders) {
+// if (!children) {
+// return;
+// }
+// Y.Object.each(binders, function(binderData, viewId) {
+// Y.Object.each(children, function(childData) {
+// if (binderData.instanceId === childData.instanceId) {
+// childData.viewId = viewId;
+// }
+// });
+// });
+// };
+
+
+// /*
+// * @method serialize_json
+// * @private
+// * @param {object} data
+// * @param {object} meta
+// * @return {string}
+// */
+// serialize_json = function(data, meta) {
+// meta.http.headers['content-type'] = ['application/json; ' + CHARSET];
+
+// try {
+// return Y.JSON.stringify(data);
+// } catch (err) {
+// throw new Error('Expected JSON data, but there was a parse error' +
+// ' on the string: \"' + data);
+// }
+
+// };
+
+
+// /*
+// * @method serialize_xml
+// * @private
+// * @param {object} data
+// * @param {object} meta
+// * @return {string}
+// */
+// serialize_xml = function(data, meta) {
+// // A dirty XML function I found on the interwebs
+// function simpleXml(js, wraptag) {
+// if (js instanceof Object) {
+// return simpleXml(Y.Object.keys(js).map(function(key) {
+// return simpleXml(js[key], key);
+// }).join('\n'), wraptag);
+// }
+
+// return ((wraptag) ? '<' + wraptag + '>' : '') + js +
+// ((wraptag) ? '</' + wraptag + '>' : ''
+// );
+// }
+
+// meta.http.headers['content-type'] = ['application/xml; ' + CHARSET];
+// if (Y.Lang.isObject) {
+// try {
+// return simpleXml(data, 'xml');
+// } catch (err) {
+// throw new Error('Expected XML data, but there was a parse' +
+// ' error on the string: \"' + err.message);
+// }
+// }
+
+// return '';
+// };
+
+
+// serializer = {
+// json: serialize_json,
+// xml: serialize_xml
+// };
+
+
+// /**
+// * <strong>Access point:</strong> <em>ac.*</em>
+// * The main API point for developers in a Controller. This addon provides
+// * the core functions
+// * of the ActionContext: <em>flush</em>, <em>done</em>, and <em>error</em>.
+// * @class OutputAdapter.common
+// * @private
+// */
+// function Addon(command, adapter, ac) {
+// /*
+// * This plugin doesn't act the same way as the others. It attaches its
+// * functions directly onto the ActionContext. Each functions is assumed
+// * that 'this' will be the actual instance of ActionContext, not the
+// * object this constructor is creating.
+// */
+// ac.flush = flush;
+// ac.done = done;
+// ac.error = error;
+// }
+
+// Addon.prototype = {
+// namespace: 'core'
+// };
+
+// Y.namespace('mojito.addons.ac').core = Addon;
}, '0.1.0', {requires: [
'json-stringify',
View
3 lib/app/addons/ac/url.common.js
@@ -120,7 +120,8 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
getRouteMaker: function() {
if (!this.maker) {
this.maker = new Y.mojito.RouteMaker(
- this.rs.getRoutes(this.context));
+ this.rs.getRoutes(this.context)
+ );
}
return this.maker;
},
View
2 lib/app/autoload/action-context.common.js
@@ -281,7 +281,7 @@ YUI.add('mojito-action-context', function(Y, NAME) {
actionFunction = command.action,
perf = Y.mojito.perf.timeline('mojito', 'ac:init', 'set up AC object', command),
error,
- staticAppConfig = YUI.Env.mojito.DataProcess.retrieve('static-app-config'),
+ staticAppConfig = YUI.Env.mojito.DataProcess.retrieve('static-app-config') || {},
my;
my = this;
View
408 lib/app/autoload/controller-context.common.js
@@ -13,210 +13,210 @@
YUI.add('mojito-controller-context', function(Y, NAME) {
-return;
-
- /**
- * @class ControllerContext
- * @constructor
- * @param {Object} opts contains instance, Y, store, appShareYUIInstance,
- * dispatch
- */
- function ControllerContext(opts) {
- this.instance = opts.instance;
- this.dispatch = opts.dispatch;
- this.store = opts.store;
- this.Y = opts.Y;
- this.shareYUIInstance = false;
- Y.mojito.util.shouldShareYUIInstance(opts.appShareYUIInstance, this.instance);
- this.init();
- }
-
-
- ControllerContext.prototype = {
-
- init: function() {
-
- var c = this.Y.mojito.controllers[this.instance['controller-module']],
- controller;
-
- controller = this.controller = Y.mojito.util.heir(c);
-
- if (Y.Lang.isFunction(controller.init)) {
- controller.init(this.instance.config);
- }
-
- return; // << RIC
-
- /*
- var error,
- // Not really an instance...more like constructor options...see
- // controller.init() call below.
- instance = this.instance,
- controller,
- shareYUIInstance = this.shareYUIInstance,
-
- // do a shallow merge of app-level and mojit-level configs
- // mojit config properties take precedence
- configApp = this.store.getAppConfig({}).config,
- configCombo = Y.merge(configApp, instance.config),
-
- // Y.mojito.controller for legacy, multi-instance.
- // Y.mojito.controllers for shared instance
- c = this.Y.mojito.controller ||
- this.Y.mojito.controllers[instance['controller-module']];
-
- // If sharing YUI and controller clobbers, log an error.
- if (shareYUIInstance && this.Y.mojito.controller) {
- this.Y.log(instance['controller-module'] + ' mojit' +
- ' clobbers Y.mojito.controller namespace. Please use' +
- ' `Y.namespace(\'mojito.controllers\')[NAME]` when ' +
- ' declaring controllers.', 'error', NAME);
- }
-
- if (!Y.Lang.isObject(c)) {
- error = new Error('Mojit controller prototype is not an' +
- ' object! (mojit id: \'' + instance.id + '\')');
-
- error.code = 500;
- throw error;
- }
-
- // we make a controller instance by using the heir() function, this
- // gives us proper function scope within the controller actions
- controller = this.controller = Y.mojito.util.heir(c);
-
- if (Y.Lang.isFunction(controller.init)) {
- // Use the instance data which isn't really an instance to
- // provide construction parameters for the controller init().
- controller.init(configCombo);
- }
-
- // mix in any (new) actions (the actions namespace here would be
- // populated by the resource store...but currently unused? Could
- // this be replaced by light inheritance to the controllers here).
- Y.Object.each(this.Y.mojito.actions, function(action, actionName) {
- this.Y.log('mixing action \'' + actionName +
- '\' into controller...', 'debug', NAME);
- controller[actionName] = function() {
- action.apply(controller, arguments);
- };
- });
-
- // stash the models this controller has available to be later
- // attached to the ActionContext
- this.models = {};
-
- Y.Object.each(this.Y.mojito.models, function(model, modelName) {
-
- if (!shareYUIInstance || (instance.models &&
- instance.models[modelName])) {
-
- // TODO: Why? There's no particular reason to inherit here.
- var modelInstance = Y.mojito.util.heir(model);
-
- if (Y.Lang.isFunction(modelInstance.init)) {
- // NOTE that we use the same config here that we use to
- // config the controller
- modelInstance.init(configCombo);
- }
- this.models[modelName] = modelInstance;
- }
- }, this);
- */
- },
-
-
- invoke: function(command, adapter) {
-
- var ac;
-
- try {
- ac = new this.Y.mojito.ActionContext({
- command: command,
- controller: this.controller,
- models: this.models,
- dispatch: this.dispatch,
- adapter: adapter,
- store: this.store
- });
- } catch (err) {
- console.log(err);
- this.Y.log('WARNING!! Uncaught error from dispatch on' +
- ' instance \'' + (command.instance.id || '@' + command.instance.type) +
- '\'', 'error', NAME);
- this.Y.log(err.message, 'error', NAME);
- this.Y.log(err.stack, 'error', NAME);
- }
-
- return; // << RIC
-
- /*
- var instance = this.instance,
- config = command.instance.config,
- // this is the action that will be executed
- action = command.action,
- ac,
- perfID,
- perf;
-
- // replace the non-expanded command instance with the proper
- // instance, that was already expanded when the controller context
- // was created
-
- // TODO: This may not be necessary...we did this in dispatch().
- // command.instance = instance;
-
- // however! we want to use the most recent config, not the cached
- // config, because that can change between action executions!
- // command.instance.config = config;
-
- // if there is no action, make 'index' the default
- // TODO: This may not be necessary...we did this in dispatch().
- if (!command.action) {
- // use instance config for default action or 'index'
- command.action = instance.action || 'index';
- }
-
- perfID = Y.mojito.perf.idFromCommand(command);
- perf = Y.mojito.perf.timeline('mojito', 'ac:ctor',
- 'create ac (which also invokes the action)', perfID);
-
- try {
- // Note: ac var is here to appease jslint.
- ac = new this.Y.mojito.ActionContext({
- command: command,
- controller: this.controller,
- models: this.models,
- dispatch: this.dispatch,
- adapter: adapter,
- store: this.store
- });
-
- // TODO: uncomment once above issue is repaired.
- // ac.invoke(command, adapter); // do it this way ;)
- } catch (err) {
- if (adapter.error) {
- adapter.error(err);
- } else {
- this.Y.log('WARNING!! Uncaught error from dispatch on' +
- ' instance \'' + (instance.id || '@' + instance.type) +
- '\'', 'error', NAME);
- this.Y.log(err.message, 'error', NAME);
- this.Y.log(err.stack, 'error', NAME);
- }
- // TODO: should we be rethrowing the error here? We log but we
- // don't ensure callers know...but then again dispatch() may
- // need this level of isolation.
- } finally {
- perf.done();
- }
-
- this.Y.mojito.perf.mark('mojito', 'core_dispatch_end', 'invoked action', perfID);
- */
- }
- };
-
- Y.namespace('mojito').ControllerContext = ControllerContext;
+ return;
+
+// /**
+// * @class ControllerContext
+// * @constructor
+// * @param {Object} opts contains instance, Y, store, appShareYUIInstance,
+// * dispatch
+// */
+// function ControllerContext(opts) {
+// this.instance = opts.instance;
+// this.dispatch = opts.dispatch;
+// this.store = opts.store;
+// this.Y = opts.Y;
+// this.shareYUIInstance = false;
+// Y.mojito.util.shouldShareYUIInstance(opts.appShareYUIInstance, this.instance);
+// this.init();
+// }
+
+
+// ControllerContext.prototype = {
+
+// init: function() {
+
+// var c = this.Y.mojito.controllers[this.instance['controller-module']],
+// controller;
+
+// controller = this.controller = Y.mojito.util.heir(c);
+
+// if (Y.Lang.isFunction(controller.init)) {
+// controller.init(this.instance.config);
+// }
+
+// return; // << RIC
+
+// /*
+// var error,
+// // Not really an instance...more like constructor options...see
+// // controller.init() call below.
+// instance = this.instance,
+// controller,
+// shareYUIInstance = this.shareYUIInstance,
+
+// // do a shallow merge of app-level and mojit-level configs
+// // mojit config properties take precedence
+// configApp = this.store.getAppConfig({}).config,
+// configCombo = Y.merge(configApp, instance.config),
+
+// // Y.mojito.controller for legacy, multi-instance.
+// // Y.mojito.controllers for shared instance
+// c = this.Y.mojito.controller ||
+// this.Y.mojito.controllers[instance['controller-module']];
+
+// // If sharing YUI and controller clobbers, log an error.
+// if (shareYUIInstance && this.Y.mojito.controller) {
+// this.Y.log(instance['controller-module'] + ' mojit' +
+// ' clobbers Y.mojito.controller namespace. Please use' +
+// ' `Y.namespace(\'mojito.controllers\')[NAME]` when ' +
+// ' declaring controllers.', 'error', NAME);
+// }
+
+// if (!Y.Lang.isObject(c)) {
+// error = new Error('Mojit controller prototype is not an' +
+// ' object! (mojit id: \'' + instance.id + '\')');
+
+// error.code = 500;
+// throw error;
+// }
+
+// // we make a controller instance by using the heir() function, this
+// // gives us proper function scope within the controller actions
+// controller = this.controller = Y.mojito.util.heir(c);
+
+// if (Y.Lang.isFunction(controller.init)) {
+// // Use the instance data which isn't really an instance to
+// // provide construction parameters for the controller init().
+// controller.init(configCombo);
+// }
+
+// // mix in any (new) actions (the actions namespace here would be
+// // populated by the resource store...but currently unused? Could
+// // this be replaced by light inheritance to the controllers here).
+// Y.Object.each(this.Y.mojito.actions, function(action, actionName) {
+// this.Y.log('mixing action \'' + actionName +
+// '\' into controller...', 'debug', NAME);
+// controller[actionName] = function() {
+// action.apply(controller, arguments);
+// };
+// });
+
+// // stash the models this controller has available to be later
+// // attached to the ActionContext
+// this.models = {};
+
+// Y.Object.each(this.Y.mojito.models, function(model, modelName) {
+
+// if (!shareYUIInstance || (instance.models &&
+// instance.models[modelName])) {
+
+// // TODO: Why? There's no particular reason to inherit here.
+// var modelInstance = Y.mojito.util.heir(model);
+
+// if (Y.Lang.isFunction(modelInstance.init)) {
+// // NOTE that we use the same config here that we use to
+// // config the controller
+// modelInstance.init(configCombo);
+// }
+// this.models[modelName] = modelInstance;
+// }
+// }, this);
+// */
+// },
+
+
+// invoke: function(command, adapter) {
+
+// var ac;
+
+// try {
+// ac = new this.Y.mojito.ActionContext({
+// command: command,
+// controller: this.controller,
+// models: this.models,
+// dispatch: this.dispatch,
+// adapter: adapter,
+// store: this.store
+// });
+// } catch (err) {
+// console.log(err);
+// this.Y.log('WARNING!! Uncaught error from dispatch on' +
+// ' instance \'' + (command.instance.id || '@' + command.instance.type) +
+// '\'', 'error', NAME);
+// this.Y.log(err.message, 'error', NAME);
+// this.Y.log(err.stack, 'error', NAME);
+// }
+
+// return; // << RIC
+
+// /*
+// var instance = this.instance,
+// config = command.instance.config,
+// // this is the action that will be executed
+// action = command.action,
+// ac,
+// perfID,
+// perf;
+
+// // replace the non-expanded command instance with the proper
+// // instance, that was already expanded when the controller context
+// // was created
+
+// // TODO: This may not be necessary...we did this in dispatch().
+// // command.instance = instance;
+
+// // however! we want to use the most recent config, not the cached
+// // config, because that can change between action executions!
+// // command.instance.config = config;
+
+// // if there is no action, make 'index' the default
+// // TODO: This may not be necessary...we did this in dispatch().
+// if (!command.action) {
+// // use instance config for default action or 'index'
+// command.action = instance.action || 'index';
+// }
+
+// perfID = Y.mojito.perf.idFromCommand(command);
+// perf = Y.mojito.perf.timeline('mojito', 'ac:ctor',
+// 'create ac (which also invokes the action)', perfID);
+
+// try {
+// // Note: ac var is here to appease jslint.
+// ac = new this.Y.mojito.ActionContext({
+// command: command,
+// controller: this.controller,
+// models: this.models,
+// dispatch: this.dispatch,
+// adapter: adapter,
+// store: this.store
+// });
+
+// // TODO: uncomment once above issue is repaired.
+// // ac.invoke(command, adapter); // do it this way ;)
+// } catch (err) {
+// if (adapter.error) {
+// adapter.error(err);
+// } else {
+// this.Y.log('WARNING!! Uncaught error from dispatch on' +
+// ' instance \'' + (instance.id || '@' + instance.type) +
+// '\'', 'error', NAME);
+// this.Y.log(err.message, 'error', NAME);
+// this.Y.log(err.stack, 'error', NAME);
+// }
+// // TODO: should we be rethrowing the error here? We log but we
+// // don't ensure callers know...but then again dispatch() may
+// // need this level of isolation.
+// } finally {
+// perf.done();
+// }
+
+// this.Y.mojito.perf.mark('mojito', 'core_dispatch_end', 'invoked action', perfID);
+// */
+// }
+// };
+
+// Y.namespace('mojito').ControllerContext = ControllerContext;
}, '0.1.0', {requires: [
'mojito-action-context',
View
6 lib/app/autoload/json-stringify-hack.server.js
@@ -4,12 +4,14 @@ Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
-YUI.add('json-stringify-hack', function(Y) {
+YUI.add('json-stringify-hack', function (Y) {
+
+ "use strict";
// More info about this hack here:
// http://yuilibrary.com/projects/yui3/ticket/2532759
// PR here:
// https://github.com/yui/yui3/pull/270
Y.JSON.stringify = JSON.stringify;
-}, '3.5.1-2' ,{requires:['json-stringify']});
+}, '3.5.1-2', {requires: ['json-stringify']});
View
308 lib/app/autoload/loader.common.js
@@ -10,160 +10,160 @@
YUI.add('mojito-loader', function(Y, NAME) {
-return;
-
- // IE has a limit of 2048-character long URLs.
- var MAX_URL_LENGTH = 2000;
-
- function Loader(appConfig, prefix) {
- // Y.log('ctor()', 'mojito', NAME);
- this.appConfig = appConfig;
- this.prefix = prefix || ''; // optional
- }
-
-
- Loader.prototype = {
-
- load: function(paths, cb) {
- var self = this,
- mod,
- script,
- scriptsToLoad = {},
- loaded = 0;
-
- paths = paths || {};
- if (!Y.Object.size(paths)) {
- cb();
- return;
- }
-
- for (mod in paths) {
- if (paths.hasOwnProperty(mod)) {
- if (!YUI.Env.mods[mod]) {
- script = paths[mod];
- if (/\.js$/i.test(script)) {
- if ('/' === script.charAt(0)) {
- script = this.prefix + script;
- }
- scriptsToLoad[script] = true;
- }
- }
- }
- }
- scriptsToLoad = Y.Object.keys(scriptsToLoad);
- if (!scriptsToLoad.length) {
- return cb();
- }
-
- Y.log('loading ' + scriptsToLoad.join(', '), 'mojito', NAME);
-
- Y.Get.script(scriptsToLoad, {
- async: true,
-
- onSuccess: function() {
- Y.log('SUCCESS', 'mojito', NAME);
- cb();
- },
-
- onFailure: function() {
- Y.log('FAILURE', 'warn', NAME);
- var err = new Error('Failed to load URLs: ' +
- scriptsToLoad.join(', '));
- cb(err);
- }
- });
- },
-
-
- _createURLlist: function(base, list) {
- var url, urls = [],
- newPart, newLength;
- if (!list.length) {
- return [];
- }
- url = base + list.shift();
- while (list.length) {
- newPart = list.shift();
- newLength = url.length + 1 + newPart.length;
- if (newLength > MAX_URL_LENGTH) {
- urls.push(url);
- url = base + newPart;
- } else {
- url += '&' + newPart;
- }
- }
- urls.push(url);
- return urls;
- },
-
-
-
- // this also pulls in dependencies
- createYuiLibComboUrl: function(modules, filter) {
- var required = {},
- comboJsParts = [],
- comboCssParts = [],
- loader,
- filterDef,
- filterDefSearchExp,
- i,
- name,
- info,
- filteredPath,
- combo = { js: [], css: [] },
- config = this.appConfig && this.appConfig.yui && this.appConfig.yui.config;
-
- filter = filter || 'min';
-
- loader = new Y.Loader((config || {}));
- for (i = 0; i < modules.length; i += 1) {
- name = modules[i];
- required[name] = true;
- }
- loader.ignoreRegistered = true;
- loader.calculate({required: required});
-
- // workaround for a bug fixed in yui-3.5.0
- Object.keys(loader.moduleInfo).forEach(function(module) {
- var m = loader.moduleInfo[module];
- YUI.Env._renderedMods[module] = m;
- });
-
- filterDef = loader.FILTER_DEFS[filter.toUpperCase()];
- if (filterDef) {
- filterDefSearchExp = new RegExp(filterDef.searchExp);
- }
-
- for (i = 0; i < loader.sorted.length; i += 1) {
- name = loader.sorted[i];
- if (('parallel' !== name) && (name.indexOf('nodejs') === -1)) {
- info = loader.moduleInfo[name];
- if (info) {
- filteredPath = (filterDef) ?
- info.path.replace(filterDefSearchExp,
- filterDef.replaceStr) :
- info.path;
-
- if ('lang/datatype-date' === name) {
- // this one is messed up
- filteredPath = 'datatype/lang/datatype-date.js';
- }
-
- if ('js' === info.type) {
- comboJsParts.push(loader.root + filteredPath);
- } else if ('css' === info.type) {
- comboCssParts.push(loader.root + filteredPath);
- }
- }
- }
- }
- combo.js = this._createURLlist(loader.comboBase, comboJsParts);
- combo.css = this._createURLlist(loader.comboBase, comboCssParts);
- return combo;
- }
- };
-
- Y.namespace('mojito').Loader = Loader;
+ return;
+
+// // IE has a limit of 2048-character long URLs.
+// var MAX_URL_LENGTH = 2000;
+
+// function Loader(appConfig, prefix) {
+// // Y.log('ctor()', 'mojito', NAME);
+// this.appConfig = appConfig;
+// this.prefix = prefix || ''; // optional
+// }
+
+
+// Loader.prototype = {
+
+// load: function(paths, cb) {
+// var self = this,
+// mod,
+// script,
+// scriptsToLoad = {},
+// loaded = 0;
+
+// paths = paths || {};
+// if (!Y.Object.size(paths)) {
+// cb();
+// return;
+// }
+
+// for (mod in paths) {
+// if (paths.hasOwnProperty(mod)) {
+// if (!YUI.Env.mods[mod]) {
+// script = paths[mod];
+// if (/\.js$/i.test(script)) {
+// if ('/' === script.charAt(0)) {
+// script = this.prefix + script;
+// }
+// scriptsToLoad[script] = true;
+// }
+// }
+// }
+// }
+// scriptsToLoad = Y.Object.keys(scriptsToLoad);
+// if (!scriptsToLoad.length) {
+// return cb();
+// }
+
+// Y.log('loading ' + scriptsToLoad.join(', '), 'mojito', NAME);
+
+// Y.Get.script(scriptsToLoad, {
+// async: true,
+
+// onSuccess: function() {
+// Y.log('SUCCESS', 'mojito', NAME);
+// cb();
+// },
+
+// onFailure: function() {
+// Y.log('FAILURE', 'warn', NAME);
+// var err = new Error('Failed to load URLs: ' +
+// scriptsToLoad.join(', '));
+// cb(err);
+// }
+// });
+// },
+
+
+// _createURLlist: function(base, list) {
+// var url, urls = [],
+// newPart, newLength;
+// if (!list.length) {
+// return [];
+// }
+// url = base + list.shift();
+// while (list.length) {
+// newPart = list.shift();
+// newLength = url.length + 1 + newPart.length;
+// if (newLength > MAX_URL_LENGTH) {
+// urls.push(url);
+// url = base + newPart;
+// } else {
+// url += '&' + newPart;
+// }
+// }
+// urls.push(url);
+// return urls;
+// },
+
+
+
+// // this also pulls in dependencies
+// createYuiLibComboUrl: function(modules, filter) {
+// var required = {},
+// comboJsParts = [],
+// comboCssParts = [],
+// loader,
+// filterDef,
+// filterDefSearchExp,
+// i,
+// name,
+// info,
+// filteredPath,
+// combo = { js: [], css: [] },
+// config = this.appConfig && this.appConfig.yui && this.appConfig.yui.config;
+
+// filter = filter || 'min';
+
+// loader = new Y.Loader((config || {}));
+// for (i = 0; i < modules.length; i += 1) {
+// name = modules[i];
+// required[name] = true;
+// }
+// loader.ignoreRegistered = true;
+// loader.calculate({required: required});
+
+// // workaround for a bug fixed in yui-3.5.0
+// Object.keys(loader.moduleInfo).forEach(function(module) {
+// var m = loader.moduleInfo[module];
+// YUI.Env._renderedMods[module] = m;
+// });
+
+// filterDef = loader.FILTER_DEFS[filter.toUpperCase()];
+// if (filterDef) {
+// filterDefSearchExp = new RegExp(filterDef.searchExp);
+// }
+
+// for (i = 0; i < loader.sorted.length; i += 1) {
+// name = loader.sorted[i];
+// if (('parallel' !== name) && (name.indexOf('nodejs') === -1)) {
+// info = loader.moduleInfo[name];
+// if (info) {
+// filteredPath = (filterDef) ?
+// info.path.replace(filterDefSearchExp,
+// filterDef.replaceStr) :
+// info.path;
+
+// if ('lang/datatype-date' === name) {
+// // this one is messed up
+// filteredPath = 'datatype/lang/datatype-date.js';
+// }
+
+// if ('js' === info.type) {
+// comboJsParts.push(loader.root + filteredPath);
+// } else if ('css' === info.type) {
+// comboCssParts.push(loader.root + filteredPath);
+// }
+// }
+// }
+// }
+// combo.js = this._createURLlist(loader.comboBase, comboJsParts);
+// combo.css = this._createURLlist(loader.comboBase, comboCssParts);
+// return combo;
+// }
+// };
+
+// Y.namespace('mojito').Loader = Loader;
}, '0.1.0', {requires: [
'get',
View
400 lib/app/autoload/logger.common.js
@@ -11,206 +11,206 @@
YUI.add('mojito-logger', function(Y, NAME) {
-return;
-
- // TODO: [Issue 70] Clean up the logger implementation.
-
- var isYuiLog = /^yui/,
- LOG_LEVEL = 'info',
- logNothingAtAllEver = false,
- defaults = {
- writer: null, //assigned below
- formatter: null, //assigned below
- timestamp: true,
- level: LOG_LEVEL,
- defaultLevel: 'info',
- yui: false,
- buffer: false,
- maxBufferSize: 1024,
- order: [
- 'DEBUG', 'MOJITO', 'INFO', 'WARN', 'ERROR', 'NONE'
- ],
- filter: {
- DEBUG: true,
- MOJITO: true,
- INFO: true,
- WARN: true,
- ERROR: true,
- NONE: true
- }
- };
-
-
- defaults.writer = function(data) {
- var i = 0;
- if (!console || !console.log) {
- // not much to do if I can't console.log. Sorry, IE6
- return;
- }
- if (Y.Lang.isArray(data)) {
- // this is a flush of many logs
- for (i = 0; i < data.length; i += 1) {
- console.log(data[i]);
- }
- } else {
- console.log.apply(console, arguments);
- }
- };
-
-
- defaults.formatter = function(msg, lvl, source, timestamp, opts, id) {
- var ts = opts.timestamp ? '(' + timestamp + ') ' : '',
- code = '',
- stack = '';
-
- if (msg instanceof Error) {
- if (msg.code) {
- code = ' ' + msg.code;
- }
- if (msg.stack) {
- stack = '\n' + msg.stack;
- }
- msg = 'Error' + code + ': ' + msg.message + stack;
- } else if (Y.Lang.isObject(msg)) {
- msg = Y.JSON.stringify(msg, null, 2);
- }
- source = source ? source + ': ' : '';
- return '[' + lvl.toUpperCase() + '] ' + ts + source + msg;
- };
-
-
- function Logger(opts, id) {
- var cnt = 0,
- order,
- lvl;
-
- this._opts = Y.merge(defaults, opts);
- this._buffer = [];
-
- if (id) {
- this._id = id;
- }
-
- order = this._opts.order || [];
- lvl = this._opts.level.toLowerCase();
-
- for (cnt = 0; cnt < order.length; cnt += 1) {
- this._opts.filter[order[cnt]] = true;
- }
- cnt = 0;
- while (cnt <= order.length) {
- if (order[cnt] && order[cnt].toLowerCase() !== lvl) {
- this._opts.filter[order[cnt]] = false;
- } else {
- break;
- }
- cnt += 1;
- }
-
- //Hmm... If the count is the same length as the order list we mean NONE
- if (cnt === order.length) {
- logNothingAtAllEver = true;
- }
-
- if (this._opts.filter.DEBUG) {
- if (!YUI._mojito) {
- YUI._mojito = {};
- }
- YUI._mojito.DEBUG = true;
- }
- }
-
-
- Logger.prototype = {
-
- log: function(msg, lvl, source) {
-
- var level,
- isYui,
- baseLevel,
- now;
-
- if (logNothingAtAllEver) {
- return;
- }
-
- now = new Date().getTime();
-
- // flush-fast if msg is {flush: true}
- if (Y.Lang.isObject(msg) && msg.flush === true) {
- return this.flush();
- }
-
- level = (lvl || this._opts.defaultLevel).toLowerCase();
- isYui = isYuiLog.test(level);
- baseLevel = isYui ? level.split('-').pop() : level;
-
- // the fat filter strips out log calls below current base log level
- if (!this._opts.filter[baseLevel.toUpperCase()]) {
- return;
- }
-
- // this strips out all YUI logs if the 'showYui' option is false
- if (isYui && !this._opts.yui) {
- return;
- }
-
- if (this._opts.buffer) {
- this._buffer.push([msg, level, source, now]);
- // auto-flush buffer if breaking max buffer size
- if (Y.Object.size(this._buffer) > this._opts.maxBufferSize) {
- this.flush();
- }
- } else {
- this._publish(msg, level, source, now);
- }
- },
-
-
- flush: function() {
- var log, logs = [];
- if (this._opts.publisher) {
- this._opts.publisher(this._buffer);
- } else {
- while (this._buffer.length) {
- log = this._buffer.shift();
- logs.push(this._opts.formatter(log[0], log[1], log[2],
- log[3], this._opts, this._id));
- }
- this._opts.writer(logs);
- }
- this._buffer = [];
- },
-
-
- setFormatter: function(f) {
- this._opts.formatter = f;
- },
-
-
- setWriter: function(w) {
- this._opts.writer = w;
- },
-
-
- setPublisher: function(p) {
- console.log('publisher set: ' + p.toString());
- this._opts.publisher = p;
- },
-
-
- _publish: function(msg, lvl, src, ts) {
- //console.log('default publisher');
- if (this._opts.publisher) {
- this._opts.publisher(msg, lvl, src, ts, this._id);
- } else {
- this._opts.writer(this._opts.formatter(msg, lvl, src, ts,
- this._opts, this._id));
- }
- }
- };
-
- Y.namespace('mojito').Logger = Logger;
+ return;
+
+// // TODO: [Issue 70] Clean up the logger implementation.
+
+// var isYuiLog = /^yui/,
+// LOG_LEVEL = 'info',
+// logNothingAtAllEver = false,
+// defaults = {
+// writer: null, //assigned below
+// formatter: null, //assigned below
+// timestamp: true,
+// level: LOG_LEVEL,
+// defaultLevel: 'info',
+// yui: false,
+// buffer: false,
+// maxBufferSize: 1024,
+// order: [
+// 'DEBUG', 'MOJITO', 'INFO', 'WARN', 'ERROR', 'NONE'
+// ],
+// filter: {
+// DEBUG: true,
+// MOJITO: true,
+// INFO: true,
+// WARN: true,
+// ERROR: true,
+// NONE: true
+// }
+// };
+
+
+// defaults.writer = function(data) {
+// var i = 0;
+// if (!console || !console.log) {
+// // not much to do if I can't console.log. Sorry, IE6
+// return;
+// }
+// if (Y.Lang.isArray(data)) {
+// // this is a flush of many logs
+// for (i = 0; i < data.length; i += 1) {
+// console.log(data[i]);
+// }
+// } else {
+// console.log.apply(console, arguments);
+// }
+// };
+
+
+// defaults.formatter = function(msg, lvl, source, timestamp, opts, id) {
+// var ts = opts.timestamp ? '(' + timestamp + ') ' : '',
+// code = '',
+// stack = '';
+
+// if (msg instanceof Error) {
+// if (msg.code) {
+// code = ' ' + msg.code;
+// }
+// if (msg.stack) {
+// stack = '\n' + msg.stack;
+// }
+// msg = 'Error' + code + ': ' + msg.message + stack;
+// } else if (Y.Lang.isObject(msg)) {
+// msg = Y.JSON.stringify(msg, null, 2);
+// }
+// source = source ? source + ': ' : '';
+// return '[' + lvl.toUpperCase() + '] ' + ts + source + msg;
+// };
+
+
+// function Logger(opts, id) {
+// var cnt = 0,
+// order,
+// lvl;
+
+// this._opts = Y.merge(defaults, opts);
+// this._buffer = [];
+
+// if (id) {
+// this._id = id;
+// }
+
+// order = this._opts.order || [];
+// lvl = this._opts.level.toLowerCase();
+
+// for (cnt = 0; cnt < order.length; cnt += 1) {
+// this._opts.filter[order[cnt]] = true;
+// }
+// cnt = 0;
+// while (cnt <= order.length) {
+// if (order[cnt] && order[cnt].toLowerCase() !== lvl) {
+// this._opts.filter[order[cnt]] = false;
+// } else {
+// break;
+// }
+// cnt += 1;
+// }
+
+// //Hmm... If the count is the same length as the order list we mean NONE
+// if (cnt === order.length) {
+// logNothingAtAllEver = true;
+// }
+
+// if (this._opts.filter.DEBUG) {
+// if (!YUI._mojito) {
+// YUI._mojito = {};
+// }
+// YUI._mojito.DEBUG = true;
+// }
+// }
+
+
+// Logger.prototype = {
+
+// log: function(msg, lvl, source) {
+
+// var level,
+// isYui,
+// baseLevel,
+// now;
+
+// if (logNothingAtAllEver) {
+// return;
+// }
+
+// now = new Date().getTime();
+
+// // flush-fast if msg is {flush: true}
+// if (Y.Lang.isObject(msg) && msg.flush === true) {
+// return this.flush();
+// }
+
+// level = (lvl || this._opts.defaultLevel).toLowerCase();
+// isYui = isYuiLog.test(level);
+// baseLevel = isYui ? level.split('-').pop() : level;
+
+// // the fat filter strips out log calls below current base log level
+// if (!this._opts.filter[baseLevel.toUpperCase()]) {
+// return;
+// }
+
+// // this strips out all YUI logs if the 'showYui' option is false
+// if (isYui && !this._opts.yui) {
+// return;
+// }
+
+// if (this._opts.buffer) {
+// this._buffer.push([msg, level, source, now]);
+// // auto-flush buffer if breaking max buffer size
+// if (Y.Object.size(this._buffer) > this._opts.maxBufferSize) {
+// this.flush();
+// }
+// } else {
+// this._publish(msg, level, source, now);
+// }
+// },
+
+
+// flush: function() {
+// var log, logs = [];
+// if (this._opts.publisher) {
+// this._opts.publisher(this._buffer);
+// } else {
+// while (this._buffer.length) {
+// log = this._buffer.shift();
+// logs.push(this._opts.formatter(log[0], log[1], log[2],
+// log[3], this._opts, this._id));
+// }
+// this._opts.writer(logs);
+// }
+// this._buffer = [];
+// },
+
+
+// setFormatter: function(f) {
+// this._opts.formatter = f;
+// },
+
+
+// setWriter: function(w) {
+// this._opts.writer = w;
+// },
+
+
+// setPublisher: function(p) {
+// console.log('publisher set: ' + p.toString());
+// this._opts.publisher = p;
+// },
+
+
+// _publish: function(msg, lvl, src, ts) {
+// //console.log('default publisher');
+// if (this._opts.publisher) {
+// this._opts.publisher(msg, lvl, src, ts, this._id);
+// } else {
+// this._opts.writer(this._opts.formatter(msg, lvl, src, ts,
+// this._opts, this._id));
+// }
+// }
+// };
+
+// Y.namespace('mojito').Logger = Logger;
}, '0.1.0', {requires: [
'mojito'
View
2 lib/app/middleware/mojito-combo-handler.js
@@ -19,7 +19,7 @@
*/
-/*jslint anon:true, sloppy:true, nomen:true*/
+/*jslint anon:true, sloppy:true, nomen:true, stupid:true*/
/*
DECLAIMER: this is VERY experimental, and the purpose of this
View
199 tests/unit/lib/app/addons/ac/test-deploy.server.js
@@ -25,21 +25,22 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
addon = null;
},
- 'YUI_config should use application.json yui.config': function() {
-
- var realRouteMaker = Y.mojito.RouteMaker;
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
+ 'YUI_config should use application.json yui.config': function() {
addon.ac = {
http: {
getHeader: function(h) {
return null;
}
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
addon.ac.context = {
@@ -78,13 +79,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
}
};
var binderMap = {};
-
- try {
- addon.constructMojitoClientRuntime(assetHandler, binderMap);
- }
- finally {
- Y.mojito.RouteMaker = realRouteMaker;
- }
+ addon.constructMojitoClientRuntime(assetHandler, binderMap);
A.areSame(1, blobs.length, 'wrong number of blobs');
var matches = blobs[0].match(/YUI_config = (.+?);/);
@@ -95,8 +90,8 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
A.areSame('klingon', config.lang, 'wrong lang used');
},
- 'test constructMojitoClientRuntime w/ a binderMap': function() {
+ 'test constructMojitoClientRuntime w/ a binderMap': function() {
var blobs = [],
assetHandler = {
addCss: function(path, location) {
@@ -120,16 +115,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
'viewId2': {
needs: 'another drink'
},
- },
- realRouteMaker = Y.mojito.RouteMaker
- ;
-
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
+ };
addon.ac = {
http: {
@@ -139,6 +125,15 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
},
context: {
lang: 'klingon'
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
@@ -158,12 +153,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
}
});
- try {
- addon.constructMojitoClientRuntime(assetHandler, binderMap);
- }
- finally {
- Y.mojito.RouteMaker = realRouteMaker;
- }
+ addon.constructMojitoClientRuntime(assetHandler, binderMap);
var expected = [
'<script type="text/javascript">',
@@ -186,8 +176,8 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
A.areSame('klingon', config.lang, 'wrong lang used');
},
- 'test application.json should honor yui.config.fetchCSS=false': function() {
+ 'test application.json should honor yui.config.fetchCSS=false': function() {
var realLoader = Y.mojito.Loader;
Y.mojito.Loader = function () {};
Y.mojito.Loader.prototype = {
@@ -199,19 +189,20 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
}
};
- var realRouteMaker = Y.mojito.RouteMaker;
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
-
addon.ac = {
http: {
getHeader: function(h) {
return null;
}
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
addon.ac.context = {
@@ -265,43 +256,29 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
addon.constructMojitoClientRuntime(assetHandler, binderMap);
}
finally {
- Y.mojito.RouteMaker = realRouteMaker;
Y.mojito.Loader = realLoader;
}
- A.areSame(2, Object.keys(counts).length, 'too many type:location pairs');
- A.areSame(2, counts['js top'], 'wrong number of js:top');
+ A.areSame(1, Object.keys(counts).length, 'too many type:location pairs');
A.areSame(1, counts['blob bottom'], 'wrong number of blob:bottom');
},
'test dependencyCalculations precomputed': function() {
- var calledYuiModules;
- var realLoader = Y.mojito.Loader;
- Y.mojito.Loader = function () {};
- Y.mojito.Loader.prototype = {
- createYuiLibComboUrl: function(yuiModules, yuiFilter) {
- calledYuiModules = yuiModules;
- return {
- 'css': ['css-1','css-2'],
- 'js': ['js-1','js-2']
- };
- }
- };
-
- var realRouteMaker = Y.mojito.RouteMaker;
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
-
addon.ac = {
http: {
getHeader: function(h) {
return null;
}
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
addon.ac.context = {
@@ -343,46 +320,26 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
};
var binderMap = {};
- try {
- addon.constructMojitoClientRuntime(assetHandler, binderMap);
- }
- finally {
- Y.mojito.RouteMaker = realRouteMaker;
- Y.mojito.Loader = realLoader;
- }
-
- AA.itemsAreEqual(['yui'], calledYuiModules);
+ addon.constructMojitoClientRuntime(assetHandler, binderMap);
A.areSame("'*'", YUI_use);
},
'test dependencyCalculations ondemand': function() {
- var calledYuiModules;
- var realLoader = Y.mojito.Loader;
- Y.mojito.Loader = function () {};
- Y.mojito.Loader.prototype = {
- createYuiLibComboUrl: function(yuiModules, yuiFilter) {
- calledYuiModules = yuiModules;
- return {
- 'css': ['css-1','css-2'],
- 'js': ['js-1','js-2']
- };
- }
- };
-
- var realRouteMaker = Y.mojito.RouteMaker;
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
-
addon.ac = {
http: {
getHeader: function(h) {
return null;
}
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
addon.ac.context = {
@@ -424,46 +381,26 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
};
var binderMap = {};
- try {
- addon.constructMojitoClientRuntime(assetHandler, binderMap);
- }
- finally {
- Y.mojito.RouteMaker = realRouteMaker;
- Y.mojito.Loader = realLoader;
- }
-
- AA.itemsAreEqual(['yui','get','loader-base','loader-rollup','loader-yui3'], calledYuiModules);
+ addon.constructMojitoClientRuntime(assetHandler, binderMap);
A.areSame("'mojito-client'", YUI_use);
},
'test dependencyCalculations precomputed+ondemand': function() {
- var calledYuiModules;
- var realLoader = Y.mojito.Loader;
- Y.mojito.Loader = function () {};
- Y.mojito.Loader.prototype = {
- createYuiLibComboUrl: function(yuiModules, yuiFilter) {
- calledYuiModules = yuiModules;
- return {
- 'css': ['css-1','css-2'],
- 'js': ['js-1','js-2']
- };
- }
- };
-
- var realRouteMaker = Y.mojito.RouteMaker;
- Y.mojito.RouteMaker = function() {};
- Y.mojito.RouteMaker.prototype = {
- getComputedRoutes: function() {
- return ['routes'];
- }
- };
-
addon.ac = {
http: {
getHeader: function(h) {
return null;
}
+ },
+ url: {
+ getRouteMaker: function() {
+ return {
+ getComputedRoutes: function() {
+ return ['routes'];
+ }
+ };
+ }
}
};
addon.ac.context = {
@@ -505,15 +442,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
};
var binderMap = {};
- try {
- addon.constructMojitoClientRuntime(assetHandler, binderMap);
- }
- finally {
- Y.mojito.RouteMaker = realRouteMaker;
- Y.mojito.Loader = realLoader;
- }
-
- AA.itemsAreEqual(['yui','get','loader-base','loader-rollup','loader-yui3'], calledYuiModules);
+ addon.constructMojitoClientRuntime(assetHandler, binderMap);
A.areSame("'mojito-client'", YUI_use);
}
};
View
2 tests/unit/lib/a