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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 var resources = []; | 46 var resources = []; |
47 visitInPostOrder(root, (n) { | 47 visitInPostOrder(root, (n) { |
48 if (n is DartSourceNode) libraries.add(n); | 48 if (n is DartSourceNode) libraries.add(n); |
49 if (n is ResourceSourceNode) resources.add(n); | 49 if (n is ResourceSourceNode) resources.add(n); |
50 }, includeParts: false); | 50 }, includeParts: false); |
51 | 51 |
52 String mainLibraryName; | 52 String mainLibraryName; |
53 var fragment = new DocumentFragment(); | 53 var fragment = new DocumentFragment(); |
54 for (var resource in resources) { | 54 for (var resource in resources) { |
55 var resourcePath = resourceOutputPath(resource.uri, root.uri); | 55 var resourcePath = resourceOutputPath(resource.uri, root.uri); |
| 56 var ext = path.extension(resourcePath); |
56 if (resource.cachingHash != null) { | 57 if (resource.cachingHash != null) { |
57 resourcePath = _addHash(resourcePath, resource.cachingHash); | 58 resourcePath = _addHash(resourcePath, resource.cachingHash); |
58 } | 59 } |
59 var ext = path.extension(resourcePath); | |
60 if (ext == '.css') { | 60 if (ext == '.css') { |
61 fragment.nodes.add(_cssInclude(resourcePath)); | 61 fragment.nodes.add(_cssInclude(resourcePath)); |
62 } else if (ext == '.js') { | 62 } else if (ext == '.js') { |
63 fragment.nodes.add(_libraryInclude(resourcePath)); | 63 fragment.nodes.add(_libraryInclude(resourcePath)); |
64 } | 64 } |
65 } | 65 } |
66 for (var lib in libraries) { | 66 for (var lib in libraries) { |
67 var info = lib.info; | 67 var info = lib.info; |
68 if (info == null) continue; | 68 if (info == null) continue; |
69 if (info.isEntry) mainLibraryName = jsLibraryName(info.library); | 69 if (info.isEntry) mainLibraryName = jsLibraryName(info.library); |
(...skipping 21 matching lines...) Expand all Loading... |
91 var code = mainLibraryName == null | 91 var code = mainLibraryName == null |
92 ? 'console.error("dev_compiler error: main was not generated");' | 92 ? 'console.error("dev_compiler error: main was not generated");' |
93 : '$mainLibraryName.main();'; | 93 : '$mainLibraryName.main();'; |
94 return parseFragment('<script>$code</script>\n'); | 94 return parseFragment('<script>$code</script>\n'); |
95 } | 95 } |
96 | 96 |
97 /// Convert the outputPath to include the hash in it. This function is the | 97 /// Convert the outputPath to include the hash in it. This function is the |
98 /// reverse of what the server does to determine whether a request needs to have | 98 /// reverse of what the server does to determine whether a request needs to have |
99 /// cache headers added to it. | 99 /// cache headers added to it. |
100 _addHash(String outPath, String hash) { | 100 _addHash(String outPath, String hash) { |
101 return path.join('cached', hash, outPath); | 101 // (the ____ prefix makes it look better in the web inspector) |
| 102 return '$outPath?____cached=$hash'; |
102 } | 103 } |
103 | 104 |
104 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); | 105 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); |
OLD | NEW |