mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 15:24:43 +00:00
cleanup work
This commit is contained in:
parent
79f868cbca
commit
be3c7a6670
1 changed files with 20 additions and 10 deletions
|
|
@ -3,7 +3,7 @@ describe('compiler', function(){
|
||||||
return jQuery(html)[0];
|
return jQuery(html)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var compiler, markup, directives, compile, log;
|
var compiler, markup, directives, widgets, compile, log;
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
log = "";
|
log = "";
|
||||||
|
|
@ -25,7 +25,8 @@ describe('compiler', function(){
|
||||||
|
|
||||||
};
|
};
|
||||||
markup = [];
|
markup = [];
|
||||||
compiler = new Compiler(markup, directives);
|
widgets = {};
|
||||||
|
compiler = new Compiler(markup, directives, widgets);
|
||||||
compile = function(html){
|
compile = function(html){
|
||||||
var e = element("<div>" + html + "</div>");
|
var e = element("<div>" + html + "</div>");
|
||||||
var view = compiler.compile(e)(e);
|
var view = compiler.compile(e)(e);
|
||||||
|
|
@ -39,7 +40,7 @@ describe('compiler', function(){
|
||||||
directives.directive = function(expression, element){
|
directives.directive = function(expression, element){
|
||||||
log += "found";
|
log += "found";
|
||||||
expect(expression).toEqual("expr");
|
expect(expression).toEqual("expr");
|
||||||
expect(element).toEqual(e);
|
expect(element.element).toEqual(e);
|
||||||
return function initFn() {
|
return function initFn() {
|
||||||
log += ":init";
|
log += ":init";
|
||||||
};
|
};
|
||||||
|
|
@ -78,17 +79,15 @@ describe('compiler', function(){
|
||||||
it('should allow creation of templates', function(){
|
it('should allow creation of templates', function(){
|
||||||
directives.duplicate = function(expr, element){
|
directives.duplicate = function(expr, element){
|
||||||
var template,
|
var template,
|
||||||
marker = document.createComment("marker"),
|
marker = document.createComment("marker");
|
||||||
parentNode = element.parentNode;
|
element.replaceWith(marker);
|
||||||
parentNode.insertBefore(marker, element);
|
|
||||||
parentNode.removeChild(element);
|
|
||||||
element.removeAttribute("ng-duplicate");
|
element.removeAttribute("ng-duplicate");
|
||||||
template = this.compile(element);
|
template = this.compile(element);
|
||||||
return function(marker) {
|
return function(marker) {
|
||||||
var parentNode = marker.parentNode;
|
var parentNode = marker.parentNode;
|
||||||
this.$eval(function() {
|
this.$eval(function() {
|
||||||
parentNode.insertBefore(
|
parentNode.insertBefore(
|
||||||
template(element.cloneNode(true)).element,
|
template(element.clone()).element,
|
||||||
marker.nextSibling);
|
marker.nextSibling);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -116,8 +115,8 @@ describe('compiler', function(){
|
||||||
it('should process markup before directives', function(){
|
it('should process markup before directives', function(){
|
||||||
markup.push(function(text, textNode, parentNode) {
|
markup.push(function(text, textNode, parentNode) {
|
||||||
if (text == 'middle') {
|
if (text == 'middle') {
|
||||||
expect(textNode.nodeValue).toEqual(text);
|
expect(textNode.text()).toEqual(text);
|
||||||
parentNode.setAttribute('ng-hello', text);
|
parentNode.attr('ng-hello', text);
|
||||||
textNode.nodeValue = 'replaced';
|
textNode.nodeValue = 'replaced';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -125,4 +124,15 @@ describe('compiler', function(){
|
||||||
expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after');
|
expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after');
|
||||||
expect(log).toEqual("hello middle");
|
expect(log).toEqual("hello middle");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should replace widgets', function(){
|
||||||
|
widgets.button = function(element) {
|
||||||
|
element.parentNode.replaceChild(button, element);
|
||||||
|
return function(element) {
|
||||||
|
log += 'init';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var scope = compile('<ng:button>push me</ng:button>');
|
||||||
|
expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue