diff --git a/lib/components.js b/lib/components.js index ad5c1112a..d9f77148a 100644 --- a/lib/components.js +++ b/lib/components.js @@ -169,7 +169,7 @@ SingletonComponentFactory.prototype.init = function(context) { // Don't call the create method for singleton components SingletonComponentFactory.prototype.create = function() {}; -App.prototype.component = function(viewName, constructor) { +App.prototype.component = function(viewName, constructor, ns) { if (typeof viewName === 'function') { constructor = viewName; viewName = null; @@ -178,15 +178,19 @@ App.prototype.component = function(viewName, constructor) { // Inherit from Component extendComponent(constructor); + // Set namespace to the component if it's passed along + if(ns) constructor.prototype.ns = ns; + // Load template view from filename if (constructor.prototype.view) { var viewFilename = constructor.prototype.view; viewName = constructor.prototype.name || path.basename(viewFilename, '.html'); + if(ns) viewName = ns + ':' + viewName; this.loadViews(viewFilename, viewName); - } else if (!viewName) { if (constructor.prototype.name) { viewName = constructor.prototype.name; + if(ns) viewName = ns + ':' + viewName; var view = this.views.register(viewName); view.template = templates.emptyTemplate; } else { @@ -194,6 +198,14 @@ App.prototype.component = function(viewName, constructor) { } } + // Load sub components + var subComponents = constructor.prototype.components; + if (subComponents) { + for(var i = 0, len = subComponents.length; i < len; i++) { + this.component(null, subComponents[i], viewName); + } + } + // Associate the appropriate view with the component type var view = this.views.find(viewName); if (!view) {