Chromium Code Reviews| 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 library dev_compiler.src.codegen.html_codegen; | 5 library dev_compiler.src.codegen.html_codegen; |
| 6 | 6 |
| 7 import 'package:html/dom.dart'; | 7 import 'package:html/dom.dart'; |
| 8 import 'package:html/parser.dart' show parseFragment; | 8 import 'package:html/parser.dart' show parseFragment; |
| 9 import 'package:logging/logging.dart' show Logger; | 9 import 'package:logging/logging.dart' show Logger; |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 /// This internally transforms the given HTML [document]. When compiling to | 21 /// This internally transforms the given HTML [document]. When compiling to |
| 22 /// JavaScript, we remove any Dart script tags, add new script tags to load our | 22 /// JavaScript, we remove any Dart script tags, add new script tags to load our |
| 23 /// runtime and the compiled code, and to execute the main method of the | 23 /// runtime and the compiled code, and to execute the main method of the |
| 24 /// application. When compiling to Dart, we ensure that the document contains a | 24 /// application. When compiling to Dart, we ensure that the document contains a |
| 25 /// single Dart script tag, but otherwise emit the original document | 25 /// single Dart script tag, but otherwise emit the original document |
| 26 /// unmodified. | 26 /// unmodified. |
| 27 String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) { | 27 String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) { |
| 28 var document = root.document.clone(true); | 28 var document = root.document.clone(true); |
| 29 var scripts = document.querySelectorAll('script[type="application/dart"]'); | 29 var scripts = document.querySelectorAll('script[type="application/dart"]'); |
| 30 if (scripts.isEmpty) { | 30 if (scripts.isEmpty) { |
| 31 _log.severe('No <script type="application/dart"> found in ${root.uri}'); | 31 _log.warning('No <script type="application/dart"> found in ${root.uri}'); |
| 32 return null; | 32 return '${document.outerHtml}\n'; |
|
vsm
2015/06/11 17:27:40
Note, todo requires --resources="todo.html". That
Jennifer Messerly
2015/06/11 18:28:25
yeah, I'd be totally fine removing this warning. A
| |
| 33 } | 33 } |
| 34 scripts.skip(1).forEach((s) { | 34 scripts.skip(1).forEach((s) { |
| 35 // TODO(sigmund): allow more than one Dart script tags? | 35 // TODO(sigmund): allow more than one Dart script tags? |
| 36 _log.warning(s.sourceSpan.message( | 36 _log.warning(s.sourceSpan.message( |
| 37 'unexpected script. Only one Dart script tag allowed ' | 37 'unexpected script. Only one Dart script tag allowed ' |
| 38 '(see https://github.com/dart-lang/dart-dev-compiler/issues/53).', | 38 '(see https://github.com/dart-lang/dart-dev-compiler/issues/53).', |
| 39 color: options.useColors ? colorOf('warning') : false)); | 39 color: options.useColors ? colorOf('warning') : false)); |
| 40 s.remove(); | 40 s.remove(); |
| 41 }); | 41 }); |
| 42 | 42 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 /// Convert the outputPath to include the hash in it. This function is the | 111 /// Convert the outputPath to include the hash in it. This function is the |
| 112 /// reverse of what the server does to determine whether a request needs to have | 112 /// reverse of what the server does to determine whether a request needs to have |
| 113 /// cache headers added to it. | 113 /// cache headers added to it. |
| 114 _addHash(String outPath, String hash) { | 114 _addHash(String outPath, String hash) { |
| 115 // (the ____ prefix makes it look better in the web inspector) | 115 // (the ____ prefix makes it look better in the web inspector) |
| 116 return '$outPath?____cached=$hash'; | 116 return '$outPath?____cached=$hash'; |
| 117 } | 117 } |
| 118 | 118 |
| 119 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); | 119 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); |
| OLD | NEW |