| OLD | NEW |
| 1 library angular.html_parser; | 1 library angular.html_parser; |
| 2 | 2 |
| 3 import 'package:html5lib/parser.dart'; | 3 import 'package:html5lib/parser.dart'; |
| 4 import 'package:html5lib/dom.dart'; | 4 import 'package:html5lib/dom.dart'; |
| 5 | 5 |
| 6 import 'package:angular/tools/selector.dart'; | 6 import 'package:angular/tools/selector.dart'; |
| 7 import 'package:angular/tools/io.dart'; | 7 import 'package:angular/tools/io.dart'; |
| 8 import 'package:angular/tools/common.dart'; | 8 import 'package:angular/tools/common.dart'; |
| 9 | 9 |
| 10 typedef NodeVisitor(Node node); | 10 typedef NodeVisitor(Node node); |
| 11 | 11 |
| 12 RegExp _MUSTACHE_REGEXP = new RegExp(r'{{([^}]*)}}'); | 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*)?$'); | 13 RegExp _NG_REPEAT_SYNTAX = new RegExp(r'^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s
+(.+)\s*)?$'); |
| 14 | 14 |
| 15 class HtmlExpressionExtractor { | 15 class HtmlExpressionExtractor { |
| 16 List<DirectiveInfo> directiveInfos; | 16 List<DirectiveInfo> directiveInfos; |
| 17 IoService ioService; |
| 17 | 18 |
| 18 HtmlExpressionExtractor(this.directiveInfos) { | 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 }); |
| 19 for (DirectiveInfo directiveInfo in directiveInfos) { | 29 for (DirectiveInfo directiveInfo in directiveInfos) { |
| 20 expressions.addAll(directiveInfo.expressions); | 30 expressions.addAll(directiveInfo.expressions); |
| 21 if (directiveInfo.template != null) { | 31 if (directiveInfo.template != null) { |
| 22 parseHtml(directiveInfo.template); | 32 _parseHtml(directiveInfo.template); |
| 23 } | 33 } |
| 24 } | 34 } |
| 25 } | 35 } |
| 26 | 36 |
| 27 Set<String> expressions = new Set<String>(); | 37 void _parseHtml(String html) { |
| 28 | |
| 29 void crawl(String root, IoService ioService) { | |
| 30 ioService.visitFs(root, (String file) { | |
| 31 if (!file.endsWith('.html')) return; | |
| 32 parseHtml(ioService.readAsStringSync(file)); | |
| 33 }); | |
| 34 } | |
| 35 | |
| 36 void parseHtml(String html) { | |
| 37 var document = parse(html); | 38 var document = parse(html); |
| 38 visitNodes([document], (Node node) { | 39 visitNodes([document], (Node node) { |
| 39 if (matchesNode(node, r'[*=/{{.*}}/]')) { | 40 if (matchesNode(node, r'[*=/{{.*}}/]')) { |
| 40 node.attributes.forEach((attrName, attrValue) { | 41 node.attributes.forEach((attrName, attrValue) { |
| 41 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { | 42 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { |
| 42 expressions.add(match.group(1)); | 43 expressions.add(match.group(1)); |
| 43 }); | 44 }); |
| 44 }); | 45 }); |
| 45 } | 46 } |
| 46 if (matchesNode(node, r':contains(/{{.*}}/)')) { | 47 if (matchesNode(node, r':contains(/{{.*}}/)')) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 visitNodes(List<Node> nodes, NodeVisitor visitor) { | 70 visitNodes(List<Node> nodes, NodeVisitor visitor) { |
| 70 for (Node node in nodes) { | 71 for (Node node in nodes) { |
| 71 visitor(node); | 72 visitor(node); |
| 72 if (node.nodes.length > 0) { | 73 if (node.nodes.length > 0) { |
| 73 visitNodes(node.nodes, visitor); | 74 visitNodes(node.nodes, visitor); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| OLD | NEW |