| 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; | |
| 18 | 17 |
| 19 HtmlExpressionExtractor(this.directiveInfos, this.ioService); | 18 HtmlExpressionExtractor(this.directiveInfos) { |
| 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) { | 19 for (DirectiveInfo directiveInfo in directiveInfos) { |
| 30 expressions.addAll(directiveInfo.expressions); | 20 expressions.addAll(directiveInfo.expressions); |
| 31 if (directiveInfo.template != null) { | 21 if (directiveInfo.template != null) { |
| 32 _parseHtml(directiveInfo.template); | 22 parseHtml(directiveInfo.template); |
| 33 } | 23 } |
| 34 } | 24 } |
| 35 } | 25 } |
| 36 | 26 |
| 37 void _parseHtml(String html) { | 27 Set<String> expressions = new Set<String>(); |
| 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) { |
| 38 var document = parse(html); | 37 var document = parse(html); |
| 39 visitNodes([document], (Node node) { | 38 visitNodes([document], (Node node) { |
| 40 if (matchesNode(node, r'[*=/{{.*}}/]')) { | 39 if (matchesNode(node, r'[*=/{{.*}}/]')) { |
| 41 node.attributes.forEach((attrName, attrValue) { | 40 node.attributes.forEach((attrName, attrValue) { |
| 42 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { | 41 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { |
| 43 expressions.add(match.group(1)); | 42 expressions.add(match.group(1)); |
| 44 }); | 43 }); |
| 45 }); | 44 }); |
| 46 } | 45 } |
| 47 if (matchesNode(node, r':contains(/{{.*}}/)')) { | 46 if (matchesNode(node, r':contains(/{{.*}}/)')) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 70 visitNodes(List<Node> nodes, NodeVisitor visitor) { | 69 visitNodes(List<Node> nodes, NodeVisitor visitor) { |
| 71 for (Node node in nodes) { | 70 for (Node node in nodes) { |
| 72 visitor(node); | 71 visitor(node); |
| 73 if (node.nodes.length > 0) { | 72 if (node.nodes.length > 0) { |
| 74 visitNodes(node.nodes, visitor); | 73 visitNodes(node.nodes, visitor); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| OLD | NEW |