From ada725e8b9de0c29991472ee5661a3858f6c9d1c Mon Sep 17 00:00:00 2001 From: Caridy Patino Date: Wed, 21 Nov 2012 18:44:11 -0500 Subject: [PATCH 1/2] contextualizing seed and groups->app settings, as well as producing secure copies of each of them. discarding duplicated entries in seed for better integration with shaker --- lib/app/addons/ac/deploy.server.js | 6 +++-- lib/app/addons/rs/yui.js | 36 ++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/app/addons/ac/deploy.server.js b/lib/app/addons/ac/deploy.server.js index cdab14b12..dcec69a83 100644 --- a/lib/app/addons/ac/deploy.server.js +++ b/lib/app/addons/ac/deploy.server.js @@ -59,8 +59,8 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) { contextServer = this.ac.context, appConfigServer = store.getAppConfig(contextServer), - appGroupConfig = store.yui.getAppGroupConfig(), - seedFiles = store.yui.getAppSeedFiles(contextServer), + appGroupConfig, + seedFiles, contextClient, appConfigClient, @@ -79,6 +79,8 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) { contextClient = Y.mojito.util.copy(contextServer); contextClient.runtime = 'client'; appConfigClient = store.getAppConfig(contextClient); + appGroupConfig = store.yui.getAppGroupConfig(contextClient); + seedFiles = store.yui.getAppSeedFiles(contextClient); clientConfig.context = contextClient; yuiConfig = Y.merge({ diff --git a/lib/app/addons/rs/yui.js b/lib/app/addons/rs/yui.js index 6f5c0ed71..fc745b273 100644 --- a/lib/app/addons/rs/yui.js +++ b/lib/app/addons/rs/yui.js @@ -228,17 +228,20 @@ YUI.add('addon-rs-yui', function(Y, NAME) { * the `yui.config.groups.app` will allow customization * of the combo handler when needed from application.json * @method getAppGroupConfig + * @param {object} ctx the context * @return {object} yui configuration for group "app" */ - getAppGroupConfig: function() { + getAppGroupConfig: function(ctx) { + var appConfig = this.get('host').getAppConfig(ctx), + yuiConfig = (appConfig.yui && appConfig.yui.config) || {}; return Y.merge({ - combine: (this.yuiConfig.combine === false) ? false : true, + combine: (yuiConfig.combine === false) ? false : true, maxURLLength: 1024, base: "/.", comboBase: "/combo~", comboSep: "~", root: "" - }, ((this.yuiConfig.groups && this.yuiConfig.groups.app) || {})); + }, ((yuiConfig.groups && yuiConfig.groups.app) || {})); }, @@ -253,13 +256,16 @@ YUI.add('addon-rs-yui', function(Y, NAME) { getAppSeedFiles: function(ctx) { var closestLang = Y.mojito.util.findClosestLang(ctx.lang, this.langs), files = [], - seed = this.yuiConfig.seed ? Y.Array(this.yuiConfig.seed) : [ + appConfig = this.get('host').getAppConfig(ctx), + yuiConfig = (appConfig.yui && appConfig.yui.config) || {}, + seed = yuiConfig.seed ? Y.Array(yuiConfig.seed) : [ 'yui-base', 'loader-base', 'loader-yui3', 'loader-app', 'loader-app-base{langPath}' ], + hash = {}, i; // adjusting lang just to be url friendly @@ -268,15 +274,21 @@ YUI.add('addon-rs-yui', function(Y, NAME) { // The seed files collection is lang aware, hence we should adjust // is on runtime. for (i = 0; i < seed.length; i += 1) { - // adjusting the seed based on {langToken} to facilitate - // the customization of the seed file url per lang. - files[i] = seed[i].replace(REGEX_LANG_PATH, closestLang); - // verifying if the file is actually a synthetic or yui module - if (this.yuiModulesRess.hasOwnProperty(files[i])) { - files[i] = this.yuiModulesRess[files[i]].url; - } else if (this.appModulesRess.hasOwnProperty(files[i])) { - files[i] = this.appModulesRess[files[i]].url; + if (hash.hasOwnProperty(seed[i])) { + Y.log('Skiping duplicated entry in yui.config.seed: ' + seed[i], 'warn', NAME); + } else { + // adjusting the seed based on {langToken} to facilitate + // the customization of the seed file url per lang. + files[i] = seed[i].replace(REGEX_LANG_PATH, closestLang); + // verifying if the file is actually a synthetic or yui module + if (this.yuiModulesRess.hasOwnProperty(files[i])) { + files[i] = this.yuiModulesRess[files[i]].url; + } else if (this.appModulesRess.hasOwnProperty(files[i])) { + files[i] = this.appModulesRess[files[i]].url; + } } + // hash table to avoid duplicated entries in the seed + hash[seed[i]] = true; } return files; From ea5b9463b113a0258a81b4941b37afc198005480 Mon Sep 17 00:00:00 2001 From: Caridy Patino Date: Mon, 26 Nov 2012 15:39:36 -0500 Subject: [PATCH 2/2] adding tests for store.yui.getAppSeedFiles and store.yui.getAppGroupConfig --- tests/unit/lib/app/addons/rs/test-yui.js | 82 +++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/tests/unit/lib/app/addons/rs/test-yui.js b/tests/unit/lib/app/addons/rs/test-yui.js index 22a93e3ee..48096ace5 100644 --- a/tests/unit/lib/app/addons/rs/test-yui.js +++ b/tests/unit/lib/app/addons/rs/test-yui.js @@ -721,8 +721,88 @@ YUI().use( 'ignore: _precomputeConfigApp()': function() { // TODO - } + }, + + 'test getAppGroupConfig': function() { + var fixtures, + store, + config; + fixtures = libpath.join(__dirname, '../../../../../fixtures/store'); + store = new MockRS({ root: fixtures }); + store.plug(Y.mojito.addons.rs.yui, { appRoot: fixtures, mojitoRoot: mojitoRoot } ); + + store.getAppConfig = function () { + return {}; + }; + config = store.yui.getAppGroupConfig({}); + A.isTrue(config.combine, 'combine should be true by default'); + A.areSame(1024, config.maxURLLength, 'maxURLLength should be 1024 by default'); + + store.getAppConfig = function () { + return { + yui: { + config: { + combine: false, + groups: { + app: { + maxURLLength: 'maxURLLength', + base: "base", + comboBase: "comboBase", + comboSep: "comboSep", + root: "root" + } + } + } + } + }; + }; + config = store.yui.getAppGroupConfig({}); + A.isFalse(config.combine, 'yui->config->combine should be the fallback for yui->config->groups->app->combine'); + A.areSame('maxURLLength', config.maxURLLength, 'yui->config->groups->app->maxURLLength should be honored'); + A.areSame('base', config.base, 'yui->config->groups->app->base should be honored'); + A.areSame('comboBase', config.comboBase, 'yui->config->groups->app->comboBase should be honored'); + A.areSame('comboSep', config.comboSep, 'yui->config->groups->app->comboSep should be honored'); + A.areSame('root', config.root, 'yui->config->groups->app->root should be honored'); + }, + + 'test getAppSeedFiles': function() { + var fixtures, + store, + seed; + fixtures = libpath.join(__dirname, '../../../../../fixtures/store'); + store = new MockRS({ root: fixtures }); + store.plug(Y.mojito.addons.rs.yui, { appRoot: fixtures, mojitoRoot: mojitoRoot } ); + store.yui.langs = { + 'en-US': true + }; // hack to avoid failures if langs array is undefined + store.getAppConfig = function () { + return {}; + }; + seed = store.yui.getAppSeedFiles({ + lang: 'en-US' + }); + A.isArray(seed); + A.areSame(5, seed.length, ''); + + store.getAppConfig = function () { + return { + yui: { + config: { + seed: ['yui-base', 'loader-app', 'foo{langPath}'] + } + } + }; + }; + seed = store.yui.getAppSeedFiles({ + lang: 'en-US' + }); + A.isArray(seed); + A.areSame(3, seed.length, ''); + A.areSame('yui-base', seed[0], 'regular modules should be in honored'); + A.areSame('loader-app', seed[1], 'regular modules should be in honored'); + A.areSame('foo_en-US', seed[2], 'lang should also be honored if the seed is using {langPath} token'); + } }));