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

Unified Diff: lib/src/html_css_fixup.dart

Issue 12474002: Support for parsing all CSS and producing one CSS file (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: Reworked URI computation and added test for URI fixup. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/html_css_fixup.dart
diff --git a/lib/src/html_css_fixup.dart b/lib/src/html_css_fixup.dart
index 4a3d0a3d0db115d9057a38b832383d4cba69e4dc..b9ee1f3d7fc34e1f0911dc0dfab3bb170e64c891 100644
--- a/lib/src/html_css_fixup.dart
+++ b/lib/src/html_css_fixup.dart
@@ -10,6 +10,7 @@ import 'package:html5lib/dom.dart';
import 'package:html5lib/dom_parsing.dart';
import 'package:csslib/visitor.dart';
+import 'file_system/path.dart';
import 'info.dart';
import 'messages.dart';
import 'options.dart';
@@ -27,12 +28,15 @@ void fixupHtmlCss(FileInfo fileInfo, CompilerOptions opts) {
// component.
if (opts.verbose) print(" CSS fixup ${fileInfo.path.filename}");
for (var component in fileInfo.declaredComponents) {
- if (component.styleSheet != null) {
+ // TODO(terry): Consider allowing more than one style sheet per component.
+ // For components only 1 stylesheet allowed.
+ if (!component.styleSheets.isEmpty && component.styleSheets.length == 1) {
+ var styleSheet = component.styleSheets[0];
// If polyfill is on prefix component name to all CSS classes and ids
// referenced in the scoped style.
var prefix = opts.processCss ? component.tagName : null;
// List of referenced #id and .class in CSS.
- var knownCss = new IdClassVisitor()..visitTree(component.styleSheet);
+ var knownCss = new IdClassVisitor()..visitTree(styleSheet);
// Prefix all id and class refs in CSS selectors and HTML attributes.
new _ScopedStyleRenamer(knownCss, prefix, opts.debugCss).visit(component);
}
@@ -75,10 +79,15 @@ Map createCssSimpleSelectors(IdClassVisitor visitedCss, ComponentInfo info,
*/
String createCssSelectorsDefinition(ComponentInfo info, bool cssPolyfill) {
var cssVisited = new IdClassVisitor();
- if (info.styleSheet != null) cssVisited..visitTree(info.styleSheet);
+
+ // For components only 1 stylesheet allowed.
+ if (!info.styleSheets.isEmpty && info.styleSheets.length == 1) {
+ var styleSheet = info.styleSheets[0];
+ cssVisited..visitTree(styleSheet);
+ }
+
var css = json.stringify(createCssSimpleSelectors(cssVisited, info,
scopedStyles: cssPolyfill));
-
return 'static Map<String, String> _css = $css;';
}
@@ -166,3 +175,19 @@ class _ScopedStyleRenamer extends InfoVisitor {
}
}
}
+
+/** Compute each CSS URI resource relative from the generated CSS file. */
+class UriVisitor extends Visitor {
+ final Path _relativePath;
+
+ UriVisitor(PathInfo pathInfo, Path mainFile, Path cssFile, bool rewriteUrl)
+ : _relativePath = cssFile.relativeTo(
+ rewriteUrl ? pathInfo.outputDirPath(mainFile) : mainFile.directoryPath
+ ).directoryPath;
Siggi Cherem (dart-lang) 2013/03/11 21:13:11 oops - this was my fault. Can you fix the indentat
terry 2013/03/11 22:09:13 Done.
+
+
+ void visitUriTerm(UriTerm node) {
+ // TODO(terry): Needs to use pathos.
+ node.text = _relativePath.join(new Path(node.text)).toString();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698