| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// This library provides a single function called injectLogs which when called | 5 /// This library provides a single function called injectLogs which when called |
| 6 /// will request a logs json file and build a small widget out of them which | 6 /// will request a logs json file and build a small widget out of them which |
| 7 /// groups the logs by level. | 7 /// groups the logs by level. |
| 8 library polymer.build.log_injector; | 8 library polymer.build.log_injector; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 // TODO(sigmund): add permanent links to error messages like in polymer. | 49 // TODO(sigmund): add permanent links to error messages like in polymer. |
| 50 for (var m in messages) { | 50 for (var m in messages) { |
| 51 var message = _hyperlinkUrls(_escape(m.message)); | 51 var message = _hyperlinkUrls(_escape(m.message)); |
| 52 var span = m.span; | 52 var span = m.span; |
| 53 var sb = new StringBuffer(); | 53 var sb = new StringBuffer(); |
| 54 sb.write('<div class="message"><div class="text $level">$message</div>'); | 54 sb.write('<div class="message"><div class="text $level">$message</div>'); |
| 55 if (span != null) { | 55 if (span != null) { |
| 56 sb.write('<div class="location">' | 56 sb.write('<div class="location">' |
| 57 ' <span class="location">${span.start.toolString}</span></div>' | 57 ' <span class="location">${span.start.toolString}</span></div>' |
| 58 ' <span class="text">${_escape(span.text)}</span></div></div>'); | 58 ' <span class="text">'); |
| 59 if (span is SourceSpanWithContext) { |
| 60 var context = span.context; |
| 61 var text = span.text; |
| 62 sb.write(_escape(context.substring(0, span.start.column))); |
| 63 sb.write('<span class="$level">'); |
| 64 sb.write(_escape(span.text)); |
| 65 sb.write('</span>'); |
| 66 sb.write(_escape(context.substring(span.end.column))); |
| 67 } else { |
| 68 sb.write(_escape(span.text)); |
| 69 } |
| 70 sb.write('</span></div></div>'); |
| 59 } | 71 } |
| 60 sb.write('</div>'); | 72 sb.write('</div>'); |
| 61 | 73 |
| 62 var logElement = new Element.html('$sb', | 74 var logElement = new Element.html('$sb', |
| 63 validator: new NodeValidatorBuilder.common() | 75 validator: new NodeValidatorBuilder.common() |
| 64 ..allowNavigation(new _OpenUriPolicy())); | 76 ..allowNavigation(new _OpenUriPolicy())); |
| 65 contentItem.append(logElement); | 77 contentItem.append(logElement); |
| 66 var messageElement = logElement.querySelector('div.text'); | 78 var messageElement = logElement.querySelector('div.text'); |
| 67 messageElement.onClick.listen((e) { | 79 messageElement.onClick.listen((e) { |
| 68 if (e.target == messageElement) { | 80 if (e.target == messageElement) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 class _Visitor extends RecursiveSummaryVisitor { | 123 class _Visitor extends RecursiveSummaryVisitor { |
| 112 final Map<String, List<MessageSummary>> messagesByLevel = {}; | 124 final Map<String, List<MessageSummary>> messagesByLevel = {}; |
| 113 | 125 |
| 114 @override | 126 @override |
| 115 void visitMessage(MessageSummary message) { | 127 void visitMessage(MessageSummary message) { |
| 116 var level = message.level.toLowerCase(); | 128 var level = message.level.toLowerCase(); |
| 117 messagesByLevel.putIfAbsent(level, () => []); | 129 messagesByLevel.putIfAbsent(level, () => []); |
| 118 messagesByLevel[level].add(message); | 130 messagesByLevel[level].add(message); |
| 119 } | 131 } |
| 120 } | 132 } |
| OLD | NEW |