aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2012-05-02 16:34:54 -0700
committerIgor Minar2012-05-03 00:15:26 -0700
commitbd530e225750e9b30b6300fc3d7447a5f1071667 (patch)
tree1e714d634691fa13af55163b038d2d276a9dfb42
parent843f762c573e38a044f920c5575c6feb46bc7226 (diff)
downloadangular.js-bd530e225750e9b30b6300fc3d7447a5f1071667.tar.bz2
chore($compile): remove obsolete <<CONTENT>> transclusion
This stuff was never documented and is an accidental leftover from the time when the compiler was rewritten. If any code depends on this, it should be rewritten to use ngTransclude directive intead.
-rw-r--r--src/ng/compile.js8
-rw-r--r--test/ng/compileSpec.js54
2 files changed, 32 insertions, 30 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index d0b6e749..17f49d68 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -127,7 +127,6 @@ function $CompileProvider($provide) {
Suffix = 'Directive',
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
- CONTENT_REGEXP = /\<\<content\>\>/i,
HAS_ROOT_ELEMENT = /^\<[\s\S]*\>$/;
@@ -569,9 +568,7 @@ function $CompileProvider($provide) {
assertNoDuplicate('template', templateDirective, directive, element);
templateDirective = directive;
- // include the contents of the original element into the template and replace the element
- var content = directiveValue.replace(CONTENT_REGEXP, element.html());
- templateNode = jqLite(content)[0];
+ templateNode = jqLite(directiveValue)[0];
if (directive.replace) {
replaceWith(rootElement, element, templateNode);
@@ -593,7 +590,7 @@ function $CompileProvider($provide) {
ii = directives.length;
} else {
- element.html(content);
+ element.html(directiveValue);
}
}
@@ -828,7 +825,6 @@ function $CompileProvider($provide) {
$http.get(asyncWidgetDirective.templateUrl, {cache: $templateCache}).
success(function(content) {
- content = trim(content).replace(CONTENT_REGEXP, html);
if (replace && !content.match(HAS_ROOT_ELEMENT)) {
throw Error('Template must have exactly one root element: ' + content);
}
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 54837bf7..74eaec8a 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -364,7 +364,7 @@ describe('$compile', function() {
$compileProvider.directive('replace', valueFn({
restrict: 'CAM',
replace: true,
- template: '<div class="log" style="width: 10px" high-log>Hello: <<CONTENT>></div>',
+ template: '<div class="log" style="width: 10px" high-log>Replace!</div>',
compile: function(element, attr) {
attr.$set('compiled', 'COMPILED');
expect(element).toBe(attr.$$element);
@@ -372,7 +372,7 @@ describe('$compile', function() {
}));
$compileProvider.directive('append', valueFn({
restrict: 'CAM',
- template: '<div class="log" style="width: 10px" high-log>Hello: <<CONTENT>></div>',
+ template: '<div class="log" style="width: 10px" high-log>Append!</div>',
compile: function(element, attr) {
attr.$set('compiled', 'COMPILED');
expect(element).toBe(attr.$$element);
@@ -382,34 +382,34 @@ describe('$compile', function() {
it('should replace element with template', inject(function($compile, $rootScope) {
- element = $compile('<div><div replace>content</div><div>')($rootScope);
- expect(element.text()).toEqual('Hello: content');
+ element = $compile('<div><div replace>ignore</div><div>')($rootScope);
+ expect(element.text()).toEqual('Replace!');
expect(element.find('div').attr('compiled')).toEqual('COMPILED');
}));
it('should append element with template', inject(function($compile, $rootScope) {
- element = $compile('<div><div append>content</div><div>')($rootScope);
- expect(element.text()).toEqual('Hello: content');
+ element = $compile('<div><div append>ignore</div><div>')($rootScope);
+ expect(element.text()).toEqual('Append!');
expect(element.find('div').attr('compiled')).toEqual('COMPILED');
}));
- it('should compile replace template', inject(function($compile, $rootScope, log) {
- element = $compile('<div><div replace medium-log>{{ "angular" }}</div><div>')
+ it('should compile template when replacing', inject(function($compile, $rootScope, log) {
+ element = $compile('<div><div replace medium-log>ignore</div><div>')
($rootScope);
$rootScope.$digest();
- expect(element.text()).toEqual('Hello: angular');
+ expect(element.text()).toEqual('Replace!');
// HIGH goes after MEDIUM since it executes as part of replaced template
expect(log).toEqual('MEDIUM; HIGH; LOG');
}));
- it('should compile append template', inject(function($compile, $rootScope, log) {
- element = $compile('<div><div append medium-log>{{ "angular" }}</div><div>')
+ it('should compile template when appending', inject(function($compile, $rootScope, log) {
+ element = $compile('<div><div append medium-log>ignore</div><div>')
($rootScope);
$rootScope.$digest();
- expect(element.text()).toEqual('Hello: angular');
+ expect(element.text()).toEqual('Append!');
expect(log).toEqual('HIGH; LOG; MEDIUM');
}));
@@ -436,23 +436,23 @@ describe('$compile', function() {
}
}));
- it('should play nice with repeater when inline', inject(function($compile, $rootScope) {
+ it('should play nice with repeater when replacing', inject(function($compile, $rootScope) {
element = $compile(
'<div>' +
- '<div ng-repeat="i in [1,2]" replace>{{i}}; </div>' +
+ '<div ng-repeat="i in [1,2]" replace></div>' +
'</div>')($rootScope);
$rootScope.$digest();
- expect(element.text()).toEqual('Hello: 1; Hello: 2; ');
+ expect(element.text()).toEqual('Replace!Replace!');
}));
- it('should play nice with repeater when append', inject(function($compile, $rootScope) {
+ it('should play nice with repeater when appending', inject(function($compile, $rootScope) {
element = $compile(
'<div>' +
- '<div ng-repeat="i in [1,2]" append>{{i}}; </div>' +
+ '<div ng-repeat="i in [1,2]" append></div>' +
'</div>')($rootScope);
$rootScope.$digest();
- expect(element.text()).toEqual('Hello: 1; Hello: 2; ');
+ expect(element.text()).toEqual('Append!Append!');
}));
@@ -494,8 +494,12 @@ describe('$compile', function() {
beforeEach(module(
function($compileProvider) {
- $compileProvider.directive('hello', valueFn({ restrict: 'CAM', templateUrl: 'hello.html' }));
- $compileProvider.directive('cau', valueFn({ restrict: 'CAM', templateUrl:'cau.html' }));
+ $compileProvider.directive('hello', valueFn({
+ restrict: 'CAM', templateUrl: 'hello.html', transclude: true
+ }));
+ $compileProvider.directive('cau', valueFn({
+ restrict: 'CAM', templateUrl:'cau.html'
+ }));
$compileProvider.directive('cError', valueFn({
restrict: 'CAM',
@@ -930,9 +934,10 @@ describe('$compile', function() {
}));
- it('should work when widget is in root element', inject(
+ it('should work when directive is on the root element', inject(
function($compile, $httpBackend, $rootScope) {
- $httpBackend.expect('GET', 'hello.html').respond('<span>3==<<content>></span>');
+ $httpBackend.expect('GET', 'hello.html').
+ respond('<span>3==<span ng-transclude></span></span>');
element = jqLite('<b class="hello">{{1+2}}</b>');
$compile(element)($rootScope);
@@ -942,9 +947,10 @@ describe('$compile', function() {
));
- it('should work when widget is a repeater', inject(
+ it('should work when directive is a repeater', inject(
function($compile, $httpBackend, $rootScope) {
- $httpBackend.expect('GET', 'hello.html').respond('<span>i=<<content>>;</span>');
+ $httpBackend.expect('GET', 'hello.html').
+ respond('<span>i=<span ng-transclude></span>;</span>');
element = jqLite('<div><b class=hello ng-repeat="i in [1,2]">{{i}}</b></div>');
$compile(element)($rootScope);