Skip to content

Commit

Permalink
fix(uiGridStyle): <br>s were being needlessly added
Browse files Browse the repository at this point in the history
  • Loading branch information
c0bra committed Dec 17, 2013
1 parent 5687723 commit ade12ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/js/directives/ui-grid-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@

var app = angular.module('ui.grid.style', []);

app.directive('uiGridStyle', ['$interpolate', function($interpolate) {
app.directive('uiGridStyle', ['$interpolate', '$sce', function($interpolate, $sce) {
return {
// restrict: 'A',
priority: 1000,
link: function(scope, element) {
var interpolateFn = $interpolate(element.text(), true);

if (interpolateFn) {
scope.$watch(interpolateFn, function(value) {
element[0].innerText = value;
element.text(value);
});
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/directives/ui-grid-style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ describe('ui.grid.style', function() {

beforeEach(module('ui.grid.style'));

beforeEach(module(function($sceProvider) {
$sceProvider.enabled(true);
}));

describe('ui-grid-style', function() {
var element, scope, compile, recompile;

Expand All @@ -30,6 +34,22 @@ describe('ui.grid.style', function() {
recompile();
expect(element.text()).toEqual('{{ foo }}');
});

it('does not create useless <br>s', function() {
element = angular.element("<style ui-grid-style>{{ foo }}</style>");
scope.foo = '\n.bar { color: red }\n';
recompile();
dump(element.html());
expect(element.html()).toEqual(scope.foo);
});

it('works when mixing text and expressions', function() {
element = angular.element("<style ui-grid-style>.blah { color: {{ color }}; }</style>");
scope.color = 'black';
recompile();
dump(element.html());
expect(element.html()).toEqual('.blah { color: black; }');
});
});

});

0 comments on commit ade12ec

Please sign in to comment.