chore(ngSanitize): extract $sanitize, ngBindHtml, linkyFilter into a module

Create build for other modules as well (ngResource, ngCookies):
- wrap into a function
- add license
- add version

Breaks `$sanitize` service, `ngBindHtml` directive and `linky` filter were moved to the `ngSanitize` module. Apps that depend on any of these will need to load `angular-sanitize.js` and include `ngSanitize` in their dependency list: `var myApp = angular.module('myApp', ['ngSanitize']);`
This commit is contained in:
Vojta Jina
2012-04-10 16:50:31 -07:00
parent e1743cc837
commit 5bcd719866
20 changed files with 301 additions and 244 deletions

View File

@@ -67,39 +67,13 @@ describe('ngBind*', function() {
});
describe('ngBindHtml', function() {
it('should set html', inject(function($rootScope, $compile) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = '<div unknown>hello</div>';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('<div>hello</div>');
}));
it('should reset html when value is null or undefined', inject(function($compile, $rootScope) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
forEach([null, undefined, ''], function(val) {
$rootScope.html = 'some val';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('some val');
$rootScope.html = val;
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('');
});
}));
});
describe('ngBindHtmlUnsafe', function() {
it('should set unsafe html', inject(function($rootScope, $compile) {
element = $compile('<div ng-bind-html-unsafe="html"></div>')($rootScope);
$rootScope.html = '<div onclick="">hello</div>';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');
expect(angular.lowercase(element.html())).toEqual('<div onclick="">hello</div>');
}));
});
});

View File

@@ -153,32 +153,6 @@ describe('filters', function() {
});
});
describe('linky', function() {
var linky;
beforeEach(inject(function($filter){
linky = $filter('linky')
}));
it('should do basic filter', function() {
expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")).
toEqual('<a href="http://ab/">http://ab/</a> ' +
'(<a href="http://a/">http://a/</a>) ' +
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c');
expect(linky(undefined)).not.toBeDefined();
});
it('should handle mailto:', function() {
expect(linky("mailto:me@example.com")).
toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("me@example.com")).
toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("send email to me@example.com, but")).
toEqual('send email to <a href="mailto:me@example.com">me@example.com</a>, but');
});
});
describe('date', function() {
var morning = new angular.mock.TzDate(+5, '2010-09-03T12:05:08.000Z'); //7am

View File

@@ -0,0 +1,25 @@
describe('ngBindHtml', function() {
beforeEach(module('ngSanitize'));
it('should set html', inject(function($rootScope, $compile) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = '<div unknown>hello</div>';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div>hello</div>');
}));
it('should reset html when value is null or undefined', inject(function($compile, $rootScope) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
angular.forEach([null, undefined, ''], function(val) {
$rootScope.html = 'some val';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('some val');
$rootScope.html = val;
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('');
});
}));
});

View File

@@ -0,0 +1,27 @@
describe('linky', function() {
var linky;
beforeEach(module('ngSanitize'));
beforeEach(inject(function($filter){
linky = $filter('linky');
}));
it('should do basic filter', function() {
expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")).
toEqual('<a href="http://ab/">http://ab/</a> ' +
'(<a href="http://a/">http://a/</a>) ' +
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c');
expect(linky(undefined)).not.toBeDefined();
});
it('should handle mailto:', function() {
expect(linky("mailto:me@example.com")).
toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("me@example.com")).
toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("send email to me@example.com, but")).
toEqual('send email to <a href="mailto:me@example.com">me@example.com</a>, but');
});
});

View File

@@ -4,6 +4,8 @@ describe('HTML', function() {
var expectHTML;
beforeEach(module('ngSanitize'));
beforeEach(inject(function($sanitize) {
expectHTML = function(html){
return expect($sanitize(html));
@@ -11,6 +13,8 @@ describe('HTML', function() {
}));
describe('htmlParser', function() {
if (angular.isUndefined(window.htmlParser)) return;
var handler, start, text;
beforeEach(function() {
handler = {
@@ -22,8 +26,8 @@ describe('HTML', function() {
};
// Since different browsers handle newlines differenttly we trim
// so that it is easier to write tests.
forEach(attrs, function(value, key){
attrs[key] = trim(value);
angular.forEach(attrs, function(value, key) {
attrs[key] = value.replace(/^\s*/, '').replace(/\s*$/, '')
});
},
chars: function(text_){
@@ -64,9 +68,9 @@ describe('HTML', function() {
expect(start).toEqual({tag:'option', attrs:{selected:'', value:''}, unary:false});
expect(text).toEqual('abc');
});
});
// THESE TESTS ARE EXECUTED WITH COMPILED ANGULAR
it('should echo html', function() {
expectHTML('hello<b class="1\'23" align=\'""\'>world</b>.').
toEqual('hello<b class="1\'23" align="&#34;&#34;">world</b>.');
@@ -141,6 +145,8 @@ describe('HTML', function() {
});
describe('htmlSanitizerWriter', function() {
if (angular.isUndefined(window.htmlSanitizeWriter)) return;
var writer, html;
beforeEach(function() {
html = '';
@@ -277,5 +283,4 @@ describe('HTML', function() {
});
});
});

View File

@@ -9,6 +9,8 @@ describe("angular.scenario.dsl", function() {
dealoc(element);
});
beforeEach(module('ngSanitize'));
beforeEach(inject(function($injector) {
eventLog = [];
$window = {