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

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: merged 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..195d2e14d6d45beae398ebe10dad9776fef62b36 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.
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 let's emit a warning instead of silently ignoring
terry 2013/03/08 20:11:24 Done.
+ 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,28 @@ class _ScopedStyleRenamer extends InfoVisitor {
}
}
}
+
+/** Compute each CSS URI resource relative from the generated CSS file. */
+class UriVisitor extends Visitor {
+ final PathInfo _pathInfo;
+ final Path _mainFilePath;
+ final Path _cssFilePath;
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 I'm having trouble understanding these fields. Wha
terry 2013/03/08 20:11:24 mainFile is the main application file (.HTML) cssF
+ String _lastCssFilePathSegment;
+
+ UriVisitor(this._pathInfo, this._mainFilePath, this._cssFilePath) {
+ var paths = _cssFilePath.segments()..removeLast();
+ _lastCssFilePathSegment = paths.length > 0 ? paths.last : "";
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 I'm confused about this... if the idea is to trans
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 seems that you can instead write: _lastCssFilePa
terry 2013/03/08 20:11:24 Done.
+ }
+
+ void visitUriTerm(UriTerm node) {
+ Path uriPath;
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 nit: use var instead of the explicit type.
terry 2013/03/08 20:11:24 Done.
+ if (_mainFilePath.directoryPath.toString() !=
+ _cssFilePath.directoryPath.toString()) {
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 _mainFilePath and _cssFilePath are final, how abou
terry 2013/03/08 20:11:24 Done. On 2013/03/07 22:14:20, Siggi Cherem (dart-
+ uriPath = new Path('$_lastCssFilePathSegment/${node.text}');
+ } else {
+ uriPath = new Path(node.text);
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 switch to just use String (you seem to create a Pa
terry 2013/03/08 20:11:24 Done.
+ }
+ String newHRef = _pathInfo.transformUrl(_mainFilePath, uriPath.toString());
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 nit: remove this variable, do the assignment direc
terry 2013/03/08 20:11:24 Done.
+ node.text = newHRef;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698