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

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

Issue 1645343002: Builds / serves multiple HTML files. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Cleanup Created 4 years, 10 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 | « no previous file | lib/src/compiler.dart » ('j') | lib/src/compiler.dart » ('J')
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 resourcePath = _addHash(resourcePath, resource.cachingHash); 63 resourcePath = _addHash(resourcePath, resource.cachingHash);
64 } 64 }
65 var attrs = element.attributes; 65 var attrs = element.attributes;
66 if (attrs.containsKey('href')) { 66 if (attrs.containsKey('href')) {
67 attrs['href'] = resourcePath; 67 attrs['href'] = resourcePath;
68 } else if (attrs.containsKey('src')) { 68 } else if (attrs.containsKey('src')) {
69 attrs['src'] = resourcePath; 69 attrs['src'] = resourcePath;
70 } 70 }
71 }); 71 });
72 72
73 var rootDir = path.dirname(root.uri.path);
74 String rootRelative(String fullPath) {
75 return path.relative(path.join(compiler.inputBaseDir, fullPath),
76 from: rootDir);
77 }
78
73 var fragment = new DocumentFragment(); 79 var fragment = new DocumentFragment();
74 for (var resource in resources) { 80 for (var resource in resources) {
75 var resourcePath = 81 var resourcePath = rootRelative(
76 resourceOutputPath(resource.uri, root.uri, options.runtimeDir); 82 resourceOutputPath(resource.uri, root.uri, options.runtimeDir));
77 var ext = path.extension(resourcePath); 83 var ext = path.extension(resourcePath);
78 if (resource.cachingHash != null) { 84 if (resource.cachingHash != null) {
79 resourcePath = _addHash(resourcePath, resource.cachingHash); 85 resourcePath = _addHash(resourcePath, resource.cachingHash);
80 } 86 }
81 if (ext == '.js') { 87 if (ext == '.js') {
82 fragment.nodes.add(libraryInclude(resourcePath)); 88 fragment.nodes.add(libraryInclude(resourcePath));
83 } else if (ext == '.css') { 89 } else if (ext == '.css') {
84 var stylesheetLink = '<link rel="stylesheet" href="$resourcePath">\n'; 90 var stylesheetLink = '<link rel="stylesheet" href="$resourcePath">\n';
85 fragment.nodes.add(parseFragment(stylesheetLink)); 91 fragment.nodes.add(parseFragment(stylesheetLink));
86 } 92 }
87 } 93 }
88 94
89 String mainLibraryName; 95 String mainLibraryName;
90 var src = scripts[0].attributes["src"]; 96 var src = scripts[0].attributes["src"];
91 var scriptUri = root.source.resolveRelativeUri(Uri.parse(src)); 97 var scriptUri = root.source.resolveRelativeUri(Uri.parse(src));
92 98
93 for (var lib in libraries) { 99 for (var lib in libraries) {
94 var info = lib.info; 100 var info = lib.info;
95 if (info == null) continue; 101 if (info == null) continue;
96 var uri = info.library.source.uri; 102 var uri = info.library.source.uri;
97 var jsPath = compiler.getModulePath(uri); 103 var jsPath = rootRelative(compiler.getModulePath(uri));
98 if (uri == scriptUri) mainLibraryName = compiler.getModuleName(uri); 104 if (uri == scriptUri) mainLibraryName = compiler.getModuleName(uri);
99 if (lib.cachingHash != null) { 105 if (lib.cachingHash != null) {
100 jsPath = _addHash(jsPath, lib.cachingHash); 106 jsPath = _addHash(jsPath, lib.cachingHash);
101 } 107 }
102 fragment.nodes.add(libraryInclude(jsPath)); 108 fragment.nodes.add(libraryInclude(jsPath));
103 } 109 }
104 fragment.nodes.add(invokeMain(mainLibraryName)); 110 fragment.nodes.add(invokeMain(mainLibraryName));
105 scripts[0].replaceWith(fragment); 111 scripts[0].replaceWith(fragment);
106 return '${document.outerHtml}\n'; 112 return '${document.outerHtml}\n';
107 } 113 }
(...skipping 18 matching lines...) Expand all
126 132
127 /// Convert the outputPath to include the hash in it. This function is the 133 /// Convert the outputPath to include the hash in it. This function is the
128 /// reverse of what the server does to determine whether a request needs to have 134 /// reverse of what the server does to determine whether a request needs to have
129 /// cache headers added to it. 135 /// cache headers added to it.
130 _addHash(String outPath, String hash) { 136 _addHash(String outPath, String hash) {
131 // (the ____ prefix makes it look better in the web inspector) 137 // (the ____ prefix makes it look better in the web inspector)
132 return '$outPath?____cached=$hash'; 138 return '$outPath?____cached=$hash';
133 } 139 }
134 140
135 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); 141 final _log = new Logger('dev_compiler.src.codegen.html_codegen');
OLDNEW
« no previous file with comments | « no previous file | lib/src/compiler.dart » ('j') | lib/src/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698