Skip to content

Commit

Permalink
Merge pull request #775 from hannu/fix-module-issue
Browse files Browse the repository at this point in the history
Fix issue when lazy loaded element overwrote last module with the same name
  • Loading branch information
varya committed Sep 7, 2015
2 parents a19bdef + 5276c90 commit cf16be9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ angular.module('sgApp', [

function loadModule($ocLazyLoad) {
if (window.filesConfig && window.filesConfig.length) {
var fileNames = [];
angular.forEach(window.filesConfig, function(file) {
fileNames.push(file.name);
var moduleNames = [];
angular.forEach(window.filesConfig, function(lazyLoadmodule) {
moduleNames.push(lazyLoadmodule.name);
});
return $ocLazyLoad.load(fileNames);
return $ocLazyLoad.load(moduleNames);
}
}

Expand Down
16 changes: 14 additions & 2 deletions lib/app/sass/styleguide-app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ Styleguide 4.4
//
// sg-angular-directive:
// name: sgAppTest
// template: demo/testDirective.html
// file: demo/testDirectiveInit.js
// file: demo/testDirective.js
//
// Styleguide 6.1
Expand All @@ -1262,11 +1262,23 @@ Styleguide 4.4
-webkit-user-select: none;
-ms-user-select: none;
padding: 0.2em;
border: 1px solid red;
border: 2px solid red;
display: initial;
cursor: pointer;
}

// Test directive2
//
// markup:
// <div sg-test-directive-two>If you see this something is wrong</div>
//
// sg-angular-directive:
// name: sgAppTest
// file: demo/testDirectiveInit.js
// file: demo/testDirectiveTwo.js
//
// Styleguide 6.2

// styleguide:ignore:start
@include styleguide_custom_styles;
// styleguide:ignore:end
Expand Down
2 changes: 1 addition & 1 deletion lib/demo/testDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Test directive is used to demo lazy loading external directive in the test project

angular.module('sgAppTest', [])
angular.module('sgAppTest')
.controller('sgAppTest', function($scope) {
$scope.clickCount = 0;
$scope.incrementClicks = function() {
Expand Down
1 change: 1 addition & 0 deletions lib/demo/testDirectiveInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module('sgAppTest', []);
16 changes: 16 additions & 0 deletions lib/demo/testDirectiveTwo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

angular.module('sgAppTest')
.controller('sgAppTest', function($scope) {
$scope.clickCount = 0;
$scope.incrementClicks = function() {
$scope.clickCount += 1;
};
})
.directive('sgTestDirectiveTwo', function() {
return {
replace: true,
restrict: 'A',
templateUrl: 'demo/testDirective.html'
};
});
20 changes: 19 additions & 1 deletion lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ function emitCompileSuccess() {
}
}

function groupModuleFiles(allModules) {
// Group modules by module name
var namedModules = _.groupBy(allModules, function(module) {
return module.name;
});

// Commbile files from every module that has the same name
return _.map(namedModules, function(modules, moduleName) {
var files = _.uniq(_.reduce(modules, function(files, singleModule) {
return files.concat(singleModule.files);
}, []));
return {
name: moduleName,
files: files
};
});
}

function generateSectionWrapperMarkup(json) {
json.section = wrapperMarkup.generateSectionWrapperMarkup(json.sections);
}
Expand Down Expand Up @@ -291,7 +309,7 @@ module.exports.generate = function(options) {
styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config),
appRoot: opt.appRoot,
socketIo: opt.server,
filesConfig: JSON.stringify(opt.filesConfig)
filesConfig: JSON.stringify(groupModuleFiles(opt.filesConfig))
}))
.pipe(pushAllFiles())
.on('finish', resolve);
Expand Down

0 comments on commit cf16be9

Please sign in to comment.