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..64f6df6d60dbcd35b28bd966b195bcd99ee02cdc 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,16 @@ class _ScopedStyleRenamer extends InfoVisitor { |
} |
} |
} |
+ |
+/** Compute each CSS URI resource relative from the generated CSS file. */ |
+class UriVisitor extends Visitor { |
+ Path _cssRelativePath; |
+ |
+ UriVisitor(Path mainFilePath, Path cssFilePath) { |
+ _cssRelativePath = cssFilePath.directoryPath.relativeTo(mainFilePath); |
+ } |
+ |
+ void visitUriTerm(UriTerm node) { |
+ node.text = '${_cssRelativePath.toString()}/${node.text}'; |
Siggi Cherem (dart-lang)
2013/03/09 01:32:10
Looks great. Note that you can remove the toString
terry
2013/03/11 21:04:25
Reworked this still wasn't quite right.
|
+ } |
+} |