Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
chore($compile): remove obsolete <<CONTENT>> transclusion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IgorMinar committed May 3, 2012
1 parent 843f762 commit bd530e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
8 changes: 2 additions & 6 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]*\>$/;


Expand Down Expand Up @@ -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);

Expand All @@ -593,7 +590,7 @@ function $CompileProvider($provide) {

ii = directives.length;
} else {
element.html(content);
element.html(directiveValue);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
54 changes: 30 additions & 24 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ 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);
}
}));
$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);
Expand All @@ -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');
}));

Expand All @@ -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!');
}));


Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit bd530e2

Please sign in to comment.