Skip to content

Commit

Permalink
Merge pull request SC5#527 from junaidrsd/dev
Browse files Browse the repository at this point in the history
Allow loading multiple directives, fixes SC5#517
  • Loading branch information
cyberixae committed Mar 27, 2015
2 parents fc4c381 + 1014333 commit fe143b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
35 changes: 22 additions & 13 deletions lib/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
})
Expand All @@ -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);
}
}
})
Expand All @@ -69,16 +65,23 @@ 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', {
url: '/:all',
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');
Expand Down Expand Up @@ -135,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;
};
Expand Down
14 changes: 2 additions & 12 deletions test/angular/unit/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit fe143b9

Please sign in to comment.