[Framework] Continue implementing fundamentals

Continue implementing classes which represent fundamental
concepts within the framework layer. WTD-518.

In particular, add methods which will be useful during the
extension resolution phase of framework start up.
This commit is contained in:
Victor Woeltjen 2014-11-03 08:44:52 -08:00
parent 12f43d1c8d
commit 0e82250c84
4 changed files with 95 additions and 10 deletions

View File

@ -1,8 +1,8 @@
/*global define*/
define(
[],
function () {
['./Constants', './Extension'],
function (Constants, Extension) {
"use strict";
@ -11,6 +11,10 @@ define(
*
* @name BundleDefinition
* @property {string} name the human-readable name of this bundle
* @property {string} sources the name of the directory which
* contains source code used by this bundle
* @property {string} resources the name of the directory which
* contains resource files used by this bundle
* @property {Object.<string,ExtensionDefinition[]>} [extensions={}]
* all extensions exposed by this bundle
*/
@ -22,26 +26,86 @@ define(
*
* @param {string} path the path to the directory containing
* this bundle
* @param {BundleDefinition} definition
* @param {BundleDefinition} bundleDefinition
* @returns {{getDefinition: Function}}
* @constructor
*/
function Bundle(path, definition) {
function Bundle(path, bundleDefinition) {
// Start with defaults
var definition = Object.create(Constants.DEFAULT_BUNDLE),
self;
// Utility function for resolving paths in this bundle
function resolvePath(elements) {
return path.concat(elements || []).join(Constants.SEPARATOR);
}
return {
// Override defaults with specifics from bundle definition
Object.keys(bundleDefinition).forEach(function (k) {
definition[k] = bundleDefinition[k];
});
return (self = {
/**
*
* @memberof Bundle#
* @returns {string}
*/
getPath: function () {
return path;
},
/**
* Get the path to this bundle's source folder. If an
* argument is provided, the path will be to the source
* file within the bundle's source file.
*
* @memberof Bundle#
* @param {string} [sourceFile] optionally, give a path to
* a specific source file in the bundle.
* @returns {string}
*/
getSourcePath: function (sourceFile) {
var subpath = sourceFile ?
[ definition.sources, sourceFile ] :
[ definition.sources ];
return resolvePath(subpath);
},
/**
* Get the path to this bundle's resource folder. If an
* argument is provided, the path will be to the resource
* file within the bundle's resource file.
*
* @memberof Bundle#
* @param {string} [resourceFile] optionally, give a path to
* a specific resource file in the bundle.
* @returns {string}
*/
getResourcePath: function (resourceFile) {
var subpath = resourceFile ?
[ definition.resources, resourceFile ] :
[ definition.resources ];
return resolvePath(subpath);
},
getExtensions: function (category) {
var extensions = definition.extensions[category] || [];
return extensions.map(function objectify(extDefinition) {
return new Extension(self, category, extDefinition);
});
},
/**
*
* @memberof Bundle#
* @returns {BundleDefinition} the raw definition of this bundle
*/
getDefinition: function () {
return definition;
}
};
});
}
new Bundle().getDefinition().extensions['k'][0].
return Bundle;
}
);

View File

@ -6,5 +6,12 @@
define({
MODULE_NAME: "OpenMCTWeb",
BUNDLE_LISTING_FILE: "bundles.json",
BUNDLE_FILE: "bundle.json"
BUNDLE_FILE: "bundle.json",
SEPARATOR: "/",
DEFAULT_BUNDLE: {
"sources": "src",
"resources": "res",
"test": "test",
"extensions": {}
}
});

View File

@ -48,6 +48,19 @@ define(
getCategory: function () {
return category;
},
/**
* Get the path to the AMD module which implements this
* extension. Will return undefined if there is no
* implementation associated with this extension.
*
* @memberof Extension#
* @returns {string} path to implementation, or undefined
*/
getImplementationPath: function () {
return definition.implementation ?
bundle.getSourcePath(definition.implementation) :
undefined;
},
/**
* @memberof Extension#
* @returns {ExtensionDefinition}

View File

@ -12,7 +12,8 @@ define(
[
'require',
'../lib/es6-promise-2.0.0.min',
'../lib/angular.min'
'../lib/angular.min',
'./BundleLoader'
],
function (require, es6promise, angular) {
"use strict";