2015-03-23 14:10:55 -07:00
|
|
|
import {RegExpWrapper, StringWrapper, isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
|
|
|
|
2015-07-11 17:26:48 +02:00
|
|
|
import {Parser} from 'angular2/src/change_detection/change_detection';
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
import {CompileStep} from './compile_step';
|
|
|
|
import {CompileElement} from './compile_element';
|
|
|
|
import {CompileControl} from './compile_control';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses interpolations in direct text child nodes of the current element.
|
|
|
|
*/
|
2015-05-18 11:57:20 -07:00
|
|
|
export class TextInterpolationParser implements CompileStep {
|
2015-06-12 23:11:11 +02:00
|
|
|
constructor(public _parser: Parser) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-05-18 11:57:20 -07:00
|
|
|
process(parent: CompileElement, current: CompileElement, control: CompileControl) {
|
2015-04-10 16:12:37 +02:00
|
|
|
if (!current.compileChildren) {
|
2015-03-23 14:10:55 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var element = current.element;
|
|
|
|
var childNodes = DOM.childNodes(DOM.templateAwareRoot(element));
|
2015-05-18 11:57:20 -07:00
|
|
|
for (var i = 0; i < childNodes.length; i++) {
|
2015-03-23 14:10:55 -07:00
|
|
|
var node = childNodes[i];
|
|
|
|
if (DOM.isTextNode(node)) {
|
2015-07-07 20:03:00 -07:00
|
|
|
var textNode = <Text>node;
|
|
|
|
var text = DOM.nodeValue(textNode);
|
2015-03-23 14:10:55 -07:00
|
|
|
var expr = this._parser.parseInterpolation(text, current.elementDescription);
|
|
|
|
if (isPresent(expr)) {
|
2015-07-07 20:03:00 -07:00
|
|
|
DOM.setText(textNode, ' ');
|
2015-06-24 13:46:39 -07:00
|
|
|
if (current.element === current.inheritedProtoView.rootElement) {
|
2015-07-07 20:03:00 -07:00
|
|
|
current.inheritedProtoView.bindRootText(textNode, expr);
|
2015-06-24 13:46:39 -07:00
|
|
|
} else {
|
2015-07-07 20:03:00 -07:00
|
|
|
current.bindElement().bindText(textNode, expr);
|
2015-06-24 13:46:39 -07:00
|
|
|
}
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|