Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix common class: add a custom wrapper element with the defined class... #308

Merged
merged 1 commit into from
Dec 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ angular.module('sgApp', [
}
};
})
.filter('addWrapper', ['Styleguide', function(Styleguide) {
return function(html) {
var cls = Styleguide.config.data.commonClass;
if (cls) {
return '<sg-custom-wrapper class="' + cls + '">' + html + '</sg-custom-wrapper>';
}
return html;
};
}])
// Trust modifier markup to be safe html
.filter('unsafe', ['$sce', function($sce) {
return function(val) {
Expand Down
4 changes: 0 additions & 4 deletions lib/app/js/controllers/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,4 @@ angular.module('sgApp')
return re.test(section.reference);
};

$scope.getCommonClass = function() {
return Styleguide.config.data.commonClass;
};

});
7 changes: 2 additions & 5 deletions lib/app/views/partials/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ <h1 class="sg"><span class="reference-number">{{ section.reference }}</span> {{
</a>
</div>
<div
ng-bind-html="mod.wrappedMarkup | setModifierClass: mod.className | setVariables: variables | unsafe " sg-scope-user-styles>
ng-bind-html="mod.wrappedMarkup | setModifierClass: mod.className | setVariables: variables | addWrapper | unsafe" sg-scope-user-styles>
</div>
</div>
<div ng-repeat-end></div>
<div
class="sg section-partial"
ng-class="getCommonClass()"
ng-if="!section.modifiers.length && section.markup">
<div class="sg label">
<a ng-href="{{section.reference}}/fullscreen" target="_blank">
<i class="fa fa-arrows-alt"></i>
</a>
</div>
<div
ng-bind-html="section.wrappedMarkup | setVariables: variables | unsafe" dynamic-compile sg-scope-user-styles>
</div>
<div ng-bind-html="section.wrappedMarkup | setVariables: variables | addWrapper | unsafe" dynamic-compile sg-scope-user-styles></div>
</div>

<div class="sg section-partial code-listing" ng-if="section.css">
Expand Down
46 changes: 43 additions & 3 deletions test/angular/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

describe('sgApp module', function() {

var module;
var appModule;

beforeEach(function() {
module = angular.mock.module('sgApp');
appModule = angular.mock.module('sgApp');
});

it('should be registered', function() {
expect(module).not.to.equal(null);
expect(appModule).not.to.equal(null);
});

describe('setModifierClass filter', function() {
Expand Down Expand Up @@ -75,4 +75,44 @@ describe('sgApp module', function() {
expect(setVariables('test string', null)).to.eql('test string');
});
});

describe('addWrapper filter', function() {

var addWrapper,
Styleguide;

beforeEach(function() {
Styleguide = {
config: {
data: {}
}
};

module(function($provide) {
$provide.value('Styleguide', Styleguide);
});

inject(function($filter) {
addWrapper = $filter('addWrapper');
});
});

it('should be defined', function() {
expect(addWrapper).to.be.a('function');
});

it('returns input as-is if Styleguide config does not have commonClass', function() {
var input = 'unchanged';
expect(addWrapper(input)).to.eql(input);
});

it('returns input wrapped inside a <sg-custom-wrapper> tag with common class if Styleguide config has commonClass', function() {
Styleguide.config.data.commonClass = 'my-common-class';
var input = 'wrapped',
expected = '<sg-custom-wrapper class="my-common-class">wrapped</sg-custom-wrapper>';
expect(addWrapper(input)).to.eql(expected);
});

});

});