Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Side by Side Diff: lib/src/codegen/html_codegen.dart

Issue 1223113005: simplify computing of runtime file locations (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/devc.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 var resources = new Set(); 44 var resources = new Set();
45 visitInPostOrder(root, (n) { 45 visitInPostOrder(root, (n) {
46 if (n is DartSourceNode) libraries.add(n); 46 if (n is DartSourceNode) libraries.add(n);
47 if (n is ResourceSourceNode) resources.add(n); 47 if (n is ResourceSourceNode) resources.add(n);
48 }, includeParts: false); 48 }, includeParts: false);
49 49
50 root.htmlResourceNodes.forEach((element, resource) { 50 root.htmlResourceNodes.forEach((element, resource) {
51 // Make sure we don't try and add this node again. 51 // Make sure we don't try and add this node again.
52 resources.remove(resource); 52 resources.remove(resource);
53 53
54 var resourcePath = resourceOutputPath(resource.uri, root.uri); 54 var resourcePath =
55 resourceOutputPath(resource.uri, root.uri, options.runtimeDir);
55 if (resource.cachingHash != null) { 56 if (resource.cachingHash != null) {
56 resourcePath = _addHash(resourcePath, resource.cachingHash); 57 resourcePath = _addHash(resourcePath, resource.cachingHash);
57 } 58 }
58 var attrs = element.attributes; 59 var attrs = element.attributes;
59 if (attrs.containsKey('href')) { 60 if (attrs.containsKey('href')) {
60 attrs['href'] = resourcePath; 61 attrs['href'] = resourcePath;
61 } else if (attrs.containsKey('src')) { 62 } else if (attrs.containsKey('src')) {
62 attrs['src'] = resourcePath; 63 attrs['src'] = resourcePath;
63 } 64 }
64 }); 65 });
65 66
66 var fragment = new DocumentFragment(); 67 var fragment = new DocumentFragment();
67 for (var resource in resources) { 68 for (var resource in resources) {
68 var resourcePath = resourceOutputPath(resource.uri, root.uri); 69 var resourcePath =
70 resourceOutputPath(resource.uri, root.uri, options.runtimeDir);
69 var ext = path.extension(resourcePath); 71 var ext = path.extension(resourcePath);
70 if (resource.cachingHash != null) { 72 if (resource.cachingHash != null) {
71 resourcePath = _addHash(resourcePath, resource.cachingHash); 73 resourcePath = _addHash(resourcePath, resource.cachingHash);
72 } 74 }
73 if (ext == '.js') { 75 if (ext == '.js') {
74 fragment.nodes.add(_libraryInclude(resourcePath)); 76 fragment.nodes.add(_libraryInclude(resourcePath));
75 } else if (ext == '.css') { 77 } else if (ext == '.css') {
76 var stylesheetLink = '<link rel="stylesheet" href="$resourcePath">\n'; 78 var stylesheetLink = '<link rel="stylesheet" href="$resourcePath">\n';
77 fragment.nodes.add(parseFragment(stylesheetLink)); 79 fragment.nodes.add(parseFragment(stylesheetLink));
78 } 80 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 112
111 /// Convert the outputPath to include the hash in it. This function is the 113 /// 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 114 /// reverse of what the server does to determine whether a request needs to have
113 /// cache headers added to it. 115 /// cache headers added to it.
114 _addHash(String outPath, String hash) { 116 _addHash(String outPath, String hash) {
115 // (the ____ prefix makes it look better in the web inspector) 117 // (the ____ prefix makes it look better in the web inspector)
116 return '$outPath?____cached=$hash'; 118 return '$outPath?____cached=$hash';
117 } 119 }
118 120
119 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); 121 final _log = new Logger('dev_compiler.src.codegen.html_codegen');
OLDNEW
« no previous file with comments | « lib/devc.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698