Skip to content

Commit dd409a4

Browse files
committed
Merge pull request #308 from jpbackman/fix-common-class
Fix common class: add a custom wrapper element with the defined class...
2 parents 5c0ab0e + dc23f40 commit dd409a4

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

lib/app/js/app.js

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ angular.module('sgApp', [
9191
}
9292
};
9393
})
94+
.filter('addWrapper', ['Styleguide', function(Styleguide) {
95+
return function(html) {
96+
var cls = Styleguide.config.data.commonClass;
97+
if (cls) {
98+
return '<sg-custom-wrapper class="' + cls + '">' + html + '</sg-custom-wrapper>';
99+
}
100+
return html;
101+
};
102+
}])
94103
// Trust modifier markup to be safe html
95104
.filter('unsafe', ['$sce', function($sce) {
96105
return function(val) {

lib/app/js/controllers/sections.js

-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,4 @@ angular.module('sgApp')
5858
return re.test(section.reference);
5959
};
6060

61-
$scope.getCommonClass = function() {
62-
return Styleguide.config.data.commonClass;
63-
};
64-
6561
});

lib/app/views/partials/section.html

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,19 @@ <h1 class="sg"><span class="reference-number">{{ section.reference }}</span> {{
2222
</a>
2323
</div>
2424
<div
25-
ng-bind-html="mod.wrappedMarkup | setModifierClass: mod.className | setVariables: variables | unsafe " sg-scope-user-styles>
25+
ng-bind-html="mod.wrappedMarkup | setModifierClass: mod.className | setVariables: variables | addWrapper | unsafe" sg-scope-user-styles>
2626
</div>
2727
</div>
2828
<div ng-repeat-end></div>
2929
<div
3030
class="sg section-partial"
31-
ng-class="getCommonClass()"
3231
ng-if="!section.modifiers.length && section.markup">
3332
<div class="sg label">
3433
<a ng-href="{{section.reference}}/fullscreen" target="_blank">
3534
<i class="fa fa-arrows-alt"></i>
3635
</a>
3736
</div>
38-
<div
39-
ng-bind-html="section.wrappedMarkup | setVariables: variables | unsafe" dynamic-compile sg-scope-user-styles>
40-
</div>
37+
<div ng-bind-html="section.wrappedMarkup | setVariables: variables | addWrapper | unsafe" dynamic-compile sg-scope-user-styles></div>
4138
</div>
4239

4340
<div class="sg section-partial code-listing" ng-if="section.css">

test/angular/app.test.js

+43-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
describe('sgApp module', function() {
44

5-
var module;
5+
var appModule;
66

77
beforeEach(function() {
8-
module = angular.mock.module('sgApp');
8+
appModule = angular.mock.module('sgApp');
99
});
1010

1111
it('should be registered', function() {
12-
expect(module).not.to.equal(null);
12+
expect(appModule).not.to.equal(null);
1313
});
1414

1515
describe('setModifierClass filter', function() {
@@ -75,4 +75,44 @@ describe('sgApp module', function() {
7575
expect(setVariables('test string', null)).to.eql('test string');
7676
});
7777
});
78+
79+
describe('addWrapper filter', function() {
80+
81+
var addWrapper,
82+
Styleguide;
83+
84+
beforeEach(function() {
85+
Styleguide = {
86+
config: {
87+
data: {}
88+
}
89+
};
90+
91+
module(function($provide) {
92+
$provide.value('Styleguide', Styleguide);
93+
});
94+
95+
inject(function($filter) {
96+
addWrapper = $filter('addWrapper');
97+
});
98+
});
99+
100+
it('should be defined', function() {
101+
expect(addWrapper).to.be.a('function');
102+
});
103+
104+
it('returns input as-is if Styleguide config does not have commonClass', function() {
105+
var input = 'unchanged';
106+
expect(addWrapper(input)).to.eql(input);
107+
});
108+
109+
it('returns input wrapped inside a <sg-custom-wrapper> tag with common class if Styleguide config has commonClass', function() {
110+
Styleguide.config.data.commonClass = 'my-common-class';
111+
var input = 'wrapped',
112+
expected = '<sg-custom-wrapper class="my-common-class">wrapped</sg-custom-wrapper>';
113+
expect(addWrapper(input)).to.eql(expected);
114+
});
115+
116+
});
117+
78118
});

0 commit comments

Comments
 (0)