Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: third_party/pkg/angular/lib/tools/html_extractor.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library angular.html_parser;
2
3 import 'package:html5lib/parser.dart';
4 import 'package:html5lib/dom.dart';
5
6 import 'selector.dart';
7 import 'io.dart';
8 import 'common.dart';
9
10 typedef NodeVisitor(Node node);
11
12 RegExp _MUSTACHE_REGEXP = new RegExp(r'{{([^}]*)}}');
13 RegExp _NG_REPEAT_SYNTAX = new RegExp(r'^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s +(.+)\s*)?$');
14
15 class HtmlExpressionExtractor {
16 List<DirectiveInfo> directiveInfos;
17 IoService ioService;
18
19 HtmlExpressionExtractor(this.directiveInfos, this.ioService);
20
21 Set<String> expressions = new Set<String>();
22
23 void crawl(root) {
24 ioService.visitFs(root, (String file) {
25 if (!file.endsWith('.html')) return;
26
27 _parseHtml(ioService.readAsStringSync(file));
28 });
29 for (DirectiveInfo directiveInfo in directiveInfos) {
30 expressions.addAll(directiveInfo.expressions);
31 if (directiveInfo.template != null) {
32 _parseHtml(directiveInfo.template);
33 }
34 }
35 }
36
37 void _parseHtml(String html) {
38 var document = parse(html);
39 visitNodes([document], (Node node) {
40 if (matchesNode(node, r'[*=/{{.*}}/]')) {
41 node.attributes.forEach((attrName, attrValue) {
42 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) {
43 expressions.add(match.group(1));
44 });
45 });
46 }
47 if (matchesNode(node, r':contains(/{{.*}}/)')) {
48 _MUSTACHE_REGEXP.allMatches(node.value).forEach((match) {
49 expressions.add(match.group(1));
50 });
51 }
52 if (matchesNode(node, r'[ng-repeat]')) {
53 var expr = _NG_REPEAT_SYNTAX.
54 firstMatch(node.attributes['ng-repeat']).group(2);
55 expressions.add(expr);
56 }
57
58 for (DirectiveInfo directiveInfo in directiveInfos) {
59 if (matchesNode(node, directiveInfo.selector)) {
60 directiveInfo.expressionAttrs.forEach((attr) {
61 if (node.attributes[attr] != null && attr != 'ng-repeat') {
62 expressions.add(node.attributes[attr]);
63 }
64 });
65 }
66 }
67 });
68 }
69
70 visitNodes(List<Node> nodes, NodeVisitor visitor) {
71 for (Node node in nodes) {
72 visitor(node);
73 if (node.nodes.length > 0) {
74 visitNodes(node.nodes, visitor);
75 }
76 }
77 }
78 }
79
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698