| 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 /// Templates used for the HTML visualization of source map information. | 5 /// Templates used for the HTML visualization of source map information. |
| 6 | 6 |
| 7 library sourcemap.html.templates; | 7 library sourcemap.html.templates; |
| 8 | 8 |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 abstract class Configurations { |
| 12 Iterable<String> get configs; |
| 13 Iterable<String> get files; |
| 14 String getPath(String config, String file); |
| 15 } |
| 16 |
| 17 void outputMultiConfigs(Uri uri, |
| 18 Configurations configurations) { |
| 19 StringBuffer sb = new StringBuffer(); |
| 20 String defaultConfig = configurations.configs.first; |
| 21 String defaultFile = configurations.files.first; |
| 22 sb.write(''' |
| 23 <html> |
| 24 <head> |
| 25 <style> |
| 26 .button { |
| 27 cursor: pointer; |
| 28 padding: 10px; |
| 29 display: inline; |
| 30 } |
| 31 iframe { |
| 32 border: 0px; |
| 33 } |
| 34 </style> |
| 35 </head> |
| 36 <body style="margin:0px;"> |
| 37 <script> |
| 38 function setAll(name, property, value) { |
| 39 var elements = document.getElementsByName(name); |
| 40 for (var i = 0; i < elements.length; i++) { |
| 41 elements[i].style[property] = value; |
| 42 } |
| 43 } |
| 44 |
| 45 var current_config; |
| 46 var current_file; |
| 47 |
| 48 function setConfig(value) { |
| 49 var property = 'text-decoration'; |
| 50 var onValue = 'underline'; |
| 51 var offValue = 'none'; |
| 52 if (current_config != value) { |
| 53 setAll('config:' + current_config, property, offValue); |
| 54 setAll('src:' + current_config + ':' + current_file, 'display', 'none'); |
| 55 current_config = value; |
| 56 setAll('config:' + current_config, property, onValue); |
| 57 setAll('src:' + current_config + ':' + current_file, 'display', 'block'); |
| 58 } |
| 59 } |
| 60 |
| 61 function setFile(value) { |
| 62 var property = 'text-decoration'; |
| 63 var onValue = 'underline'; |
| 64 var offValue = 'none'; |
| 65 if (current_file != value) { |
| 66 setAll('file:' + current_file, property, offValue); |
| 67 setAll('src:' + current_config + ':' + current_file, 'display', 'none'); |
| 68 current_file = value; |
| 69 setAll('file:' + current_file, property, onValue); |
| 70 setAll('src:' + current_config + ':' + current_file, 'display', 'block'); |
| 71 } |
| 72 } |
| 73 </script> |
| 74 '''); |
| 75 for (String config in configurations.configs) { |
| 76 for (String file in configurations.files) { |
| 77 String uri = configurations.getPath(config, file); |
| 78 sb.write(''' |
| 79 <div name="src:$config:$file" |
| 80 style="width:100%;position:absolute;display:none;"> |
| 81 <iframe src="$uri" style="width:100%;height:100%;"> |
| 82 </iframe> |
| 83 </div> |
| 84 '''); |
| 85 } |
| 86 } |
| 87 sb.write(''' |
| 88 <div style="right:0px;height:30px;background-color:#E0E0E0;position:fixed;"> |
| 89 file: |
| 90 '''); |
| 91 for (String file in configurations.files) { |
| 92 sb.write(''' |
| 93 <h3 class="button" name="file:$file" |
| 94 onclick="setFile('$file');">$file</h3> |
| 95 '''); |
| 96 } |
| 97 sb.write(''' |
| 98 config: |
| 99 '''); |
| 100 for (String config in configurations.configs) { |
| 101 sb.write(''' |
| 102 <h3 class="button" name="config:$config" |
| 103 onclick="setConfig('$config');">$config</h3> |
| 104 '''); |
| 105 } |
| 106 sb.write(''' |
| 107 </div> |
| 108 <script> |
| 109 setConfig('$defaultConfig'); |
| 110 setFile('$defaultFile'); |
| 111 </script> |
| 112 </body> |
| 113 </html>'''); |
| 114 output(uri, sb.toString()); |
| 115 } |
| 116 |
| 11 /// Outputs JavaScript/Dart source mapping traces into [uri]. | 117 /// Outputs JavaScript/Dart source mapping traces into [uri]. |
| 12 void outputJsDartTrace( | 118 void outputJsDartTrace( |
| 13 Uri uri, | 119 Uri uri, |
| 14 String jsCodeHtml, | 120 String jsCodeHtml, |
| 15 String dartCodeHtml, | 121 String dartCodeHtml, |
| 16 String jsTraceHtml) { | 122 String jsTraceHtml) { |
| 17 String html = ''' | 123 String html = ''' |
| 18 <div class="js-buffer"> | 124 <div class="js-buffer"> |
| 19 ${jsCodeHtml} | 125 ${jsCodeHtml} |
| 20 </div> | 126 </div> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 </html> | 233 </html> |
| 128 '''); | 234 '''); |
| 129 } | 235 } |
| 130 | 236 |
| 131 /// Outputs [html] in [uri]. | 237 /// Outputs [html] in [uri]. |
| 132 void output(Uri uri, | 238 void output(Uri uri, |
| 133 String html) { | 239 String html) { |
| 134 File outputFile = new File.fromUri(uri); | 240 File outputFile = new File.fromUri(uri); |
| 135 outputFile.writeAsStringSync(html); | 241 outputFile.writeAsStringSync(html); |
| 136 } | 242 } |
| OLD | NEW |