From e3f01ba37a25450255d7d62ee14f21fa35269c19 Mon Sep 17 00:00:00 2001 From: Junaid Date: Thu, 26 Mar 2015 12:14:07 +0200 Subject: [PATCH 1/2] fix #517 can only load one directive at a time --- lib/app/js/app.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/app/js/app.js b/lib/app/js/app.js index 6eb0ed5c..77472ccf 100644 --- a/lib/app/js/app.js +++ b/lib/app/js/app.js @@ -45,9 +45,7 @@ angular.module('sgApp', [ controller: 'SectionsCtrl', resolve: { loadLazyModule: function($ocLazyLoad) { - if (window.filesConfig && window.filesConfig.length) { - return $ocLazyLoad.load(window.filesConfig[0].name); - } + loadModule($ocLazyLoad); } } }) @@ -57,9 +55,7 @@ angular.module('sgApp', [ controller: 'VariablesCtrl', resolve: { loadLazyModule: function($ocLazyLoad) { - if (window.filesConfig && window.filesConfig.length) { - return $ocLazyLoad.load(window.filesConfig[0].name); - } + loadModule($ocLazyLoad); } } }) @@ -69,9 +65,7 @@ angular.module('sgApp', [ controller: 'ElementCtrl', resolve: { loadLazyModule: function($ocLazyLoad) { - if (window.filesConfig && window.filesConfig.length) { - return $ocLazyLoad.load(window.filesConfig[0].name); - } + loadModule($ocLazyLoad); } } }).state('app.index.404', { @@ -79,6 +73,15 @@ angular.module('sgApp', [ templateUrl: 'views/404.html' }); + function loadModule($ocLazyLoad) { + if (window.filesConfig && window.filesConfig.length) { + var fileNames = []; + angular.forEach(window.filesConfig, function(file) { + fileNames.push(file.name); + }); + return $ocLazyLoad.load(fileNames); + } + } $locationProvider.html5Mode(true); localStorageServiceProvider.setPrefix('sgLs'); From 101433315fa7e031d6ecf0345c1af4f346152dfd Mon Sep 17 00:00:00 2001 From: Junaid Date: Thu, 26 Mar 2015 16:17:20 +0200 Subject: [PATCH 2/2] Variables wrong value fixes --- lib/app/js/app.js | 14 ++++++++++---- test/angular/unit/app.test.js | 14 ++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/app/js/app.js b/lib/app/js/app.js index 77472ccf..9b84c1ea 100644 --- a/lib/app/js/app.js +++ b/lib/app/js/app.js @@ -138,10 +138,16 @@ angular.module('sgApp', [ if (!str) { return ''; } - angular.forEach(variables, function(variable) { - if (str.match(new RegExp('\\$' + variable.name + ';', 'g'))) { - str = str.replace(new RegExp('\\$' + variable.name, 'g'), variable.value); - } + + var sortedVariables; + if (variables) { + sortedVariables = variables.slice().sort(function(a, b) { + return b.name.length - a.name.length; + }); + } + + angular.forEach(sortedVariables, function(variable) { + str = str.replace(new RegExp('\\$' + variable.name, 'g'), variable.value); }); return str; }; diff --git a/test/angular/unit/app.test.js b/test/angular/unit/app.test.js index 8560ae77..20d503da 100644 --- a/test/angular/unit/app.test.js +++ b/test/angular/unit/app.test.js @@ -59,22 +59,12 @@ describe('sgApp module', function() { }); it('should set variables correctly if the first vairbale name is seconds substring', function() { - var input = 'background: $bgColor; color: $bgColor;', + var input = 'background: $bgColor; color: $bgColor-light;', variables = [ {name: 'bgColor', value: '#FF0000'}, {name: 'bgColor-light', value: '#00FF00'} ], - result = 'background: #FF0000; color: #FF0000;'; - expect(setVariables(input, variables)).to.eql(result); - }); - - it('should set variables correctly if the second vairbale name has first vairbale name as substring', function() { - var input = 'background: $bgColor-light; color: $bgColor-light;', - variables = [ - {name: 'bgColor', value: '#FF0000'}, - {name: 'bgColor-light', value: '#00FF00'} - ], - result = 'background: #00FF00; color: #00FF00;'; + result = 'background: #FF0000; color: #00FF00;'; expect(setVariables(input, variables)).to.eql(result); });