diff --git a/src/mvc/Application.js b/src/mvc/Application.js index 0d85851f..0eb061e0 100755 --- a/src/mvc/Application.js +++ b/src/mvc/Application.js @@ -6,8 +6,7 @@ define(function(require) { EventDispatcher = require('lavaca/events/EventDispatcher'), router = require('lavaca/mvc/Router'), viewManager = require('lavaca/mvc/ViewManager'), - Connectivity = require('lavaca/net/Connectivity'), - Config = require('lavaca/util/Config'); + Connectivity = require('lavaca/net/Connectivity'); function _stopEvent(e) { e.preventDefault(); @@ -53,7 +52,7 @@ define(function(require) { this._callback = callback.bind(this); } Device.init(function() { - this.beforeInit(Config) + this.beforeInit() .then(this.init.bind(this)); }.bind(this)); }, { @@ -223,11 +222,9 @@ define(function(require) { * Handles asynchronous requests that need to happen before Application.init() is called in the constructor * @method {String} beforeInit * - * @param {Lavaca.util.Config} Config cache that's been initialized - * * @return {Promise} A promise */ - beforeInit: function(Config) { + beforeInit: function() { return Promise.resolve(null); } }); diff --git a/src/mvc/Model.js b/src/mvc/Model.js index ef581833..e1482563 100755 --- a/src/mvc/Model.js +++ b/src/mvc/Model.js @@ -6,8 +6,7 @@ define(function(require) { clone = require('mout/lang/deepClone'), contains = require('mout/array/contains'), removeAll = require('mout/array/removeAll'), - merge = require('mout/object/merge'), - Config = require('lavaca/util/Config'); + merge = require('mout/object/merge'); var UNDEFINED; @@ -382,23 +381,6 @@ define(function(require) { return _isValid(messages); } }, - /** - * Converts a relative path to an absolute api url based on environment config 'apiRoot' - * @method getApiURL - * - * @param {String} relPath A relative path - * @return {String} A formated api url or an apparently bad url '/please_set_model_url' if relPath argument is faslsy - */ - getApiURL: function(relPath) { - var badURL = '/please_set_model_url', - apiRoot = Config.get('apiRoot'), - apiURL; - if (!relPath) { - return badURL; - } - apiURL = (apiRoot || '') + relPath; - return apiURL; - }, /** * Converts this model to a key-value hash * @method toObject diff --git a/src/util/Config.js b/src/util/Config.js deleted file mode 100755 index 65bced8a..00000000 --- a/src/util/Config.js +++ /dev/null @@ -1,88 +0,0 @@ -define(function(require) { - - var Cache = require('./Cache'), - Map = require('./Map'); - - var _cache = new Cache(); - - function _construct(name, src, code) { - if (code) { - code = JSON.parse(code); - } - return new Config(name, src, code); - } - - /** - * Configuration management type - * @class lavaca.util.Config - * @extends lavaca.util.Map - */ - var Config = Map.extend({ - // Empty (no overrides) - }); - /** - * Sets the application's default config - * @method setDefault - * @static - * - * @param {String} name The name of the default config - */ - Config.setDefault = function(name) { - Map.setDefault(_cache, name); - }; - /** - * Gets the application's current config environment name - * @method currentEnvironment - * @static - * - * @return {String} The name of the current environment - */ - Config.currentEnvironment = function() { - return _cache.get('default').name; - }; - /** - * Retrieves a value from the configuration - * @method get - * @static - * @param {String} code The name of the parameter - * @return {Object} The value of the parameter - */ - /** - * Retrieves a value from the configuration - * @method get - * @static - * @param {String} name The name of the config - * @param {String} code The name of the parameter - * @return {Object} The value of the parameter - */ - Config.get = function(name, code) { - return Map.get(_cache, name, code, 'default'); - }; - /** - * Scans the document for all translations and prepares them - * @method init - * @static - */ - /** - * Scans the document for all translations and prepares them - * @method init - * @static - * @param {jQuery} scope The element to which to limit the scan - */ - Config.init = function(scope) { - Map.init(_cache, 'text/x-config', _construct, scope); - }; - /** - * Disposes of all translations - * @method dispose - * @static - */ - Config.dispose = function() { - Map.dispose(_cache); - }; - - Config.init(); - - return Config; - -}); diff --git a/src/util/Map.js b/src/util/Map.js deleted file mode 100755 index 1c606154..00000000 --- a/src/util/Map.js +++ /dev/null @@ -1,209 +0,0 @@ -define(function(require) { - - var $ = require('$'), - Cache = require('./Cache'), - Disposable = require('./Disposable'); - - function _absolute(url) { - if (url && url.indexOf('http') !== 0) { - if (url.charAt(0) === '/') { - url = location.protocol + '//' - + location.hostname - + (location.port ? ':' + location.port : '') - + (url.indexOf('/') === 0 ? url : '/' + url); - } else { - url = location.toString().split('#')[0].split('?')[0].replace(/\w+\.\w+$/, '') + url; - } - } - return url; - } - - /** - * Abstract type for lookup tables - * @class lavaca.util.Map - * @extends lavaca.util.Disposable - * - * @constructor - * @param {String} name The name of the map - * @param {String} src The URL of the map's data (or null if code is supplied) - * @param {String} code The raw string data for the map (or null if src is supplied) - */ - var Map = Disposable.extend(function(name, src, code) { - Disposable.call(this); - /** - * Whether or not the map has loaded - * @property {Boolean} hasLoaded - * @default false - */ - this.hasLoaded = false; - /** - * The name of the map - * @property {String} name - * @default null - */ - this.name = name; - /** - * The source URL for the map - * @property {String} src - * @default null - */ - this.src = _absolute(src); - /** - * The raw string data for the map - * @property {String} code - * @default null - */ - this.code = code; - /** - * The cache in which this map stores data - * @property {Lavaca.util.Cache} cache - * @default new Lavaca.util.Cache() - */ - this.cache = new Cache(); - }, { - /** - * Determines whether or not this is the desired lookup - * @method is - * - * @param {String} name The name of the lookup - * @return {Boolean} True if this is the lookup - */ - is: function(name) { - return this.name === name; - }, - /** - * Gets the value stored under a code - * @method get - * - * @param {String} code The code - * @return {Object} The value (or null) - */ - get: function(code) { - if (!this.hasLoaded) { - if (this.code) { - this.add(this.code); - } else if (this.src) { - this.load(this.src); - } - this.hasLoaded = true; - } - return this.cache.get(code); - }, - /** - * Adds parameters to this map - * @method add - * - * @param {Object} data The parameters to add - */ - add: function(data) { - for (var n in data) { - this.cache.set(n, data[n]); - } - }, - /** - * Processes server data to include in this lookup - * @method process - * - * @param {String} text The server data string - */ - process: function(text) { - this.add(typeof text === 'string' ? JSON.parse(text) : text); - }, - /** - * Adds JSON data to this map (synchronous) - * @method load - * - * @param {String} url The URL of the data - */ - load: function(url) { - var self = this; - $.ajax({ - async: false, - url: url, - success: function(resp) { - self.process(resp); - } - }); - } - }); - /** - * Sets the application's default config - * @method setDefault - * @static - * - * @param {Lavaca.util.Cache} cache The map cache - * @param {String} name The name of the config - */ - Map.setDefault = function(cache, name) { - var map = name; - if (typeof map === 'string') { - map = cache.get(name); - } - cache.set('default', map); - }; - /** - * Finds the most appropriate value for a code - * @method get - * @static - * - * @param {Lavaca.util.Cache} cache The maps cache - * @param {String} name The name of the map - * @param {String} code The name of the parameter - * @param {String} defaultName The name of the default map - * @return {Object} The value of the parameter - */ - Map.get = function(cache, name, code, defaultName) { - if (!code) { - code = name; - name = defaultName; - } - if (name) { - var map = cache.get(name); - if (map) { - return map.get(code); - } - } - return null; - }; - /** - * Scans the document for all maps and prepares them - * @method init - * @static - * - * @param {Lavaca.util.Cache} cache The map cache - * @param {String} mimeType The MIME type of the scripts - * @param {Function} construct A function that returns a new map, in - * the form construct(name, src, code) - * @param {jQuery} scope The element to which to limit the scan - */ - Map.init = function(cache, mimeType, construct, scope) { - $(scope || document.documentElement) - .find('script[type="' + mimeType + '"]') - .each(function() { - var item = $(this), - src = item.attr('data-src'), - name = item.attr('data-name'), - isDefault = typeof item.attr('data-default') === 'string', - code = item.text(), - map; - map = construct(name, src, code); - cache.set(map.name, map); - if (isDefault) { - Map.setDefault(cache, name); - } - }); - }; - /** - * Disposes of all maps - * @method dispose - * @static - * - * @param {Lavaca.util.Cache} cache The map cache - */ - Map.dispose = function(cache) { - cache.dispose(); - }; - - return Map; - -}); diff --git a/test/unit/util/Config.js b/test/unit/util/Config.js deleted file mode 100755 index 2ef8be3e..00000000 --- a/test/unit/util/Config.js +++ /dev/null @@ -1,40 +0,0 @@ -define(function(require) { - - var $ = require('$'); - var Config = require('lavaca/util/Config'); - - var scope = '.scripts'; - - describe('A Config', function() { - beforeEach(function() { - var result = []; - result.push('