OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 3 |
4 import 'package:csslib/parser.dart' as css; | 4 import 'package:csslib/parser.dart' as css; |
5 import 'package:csslib/visitor.dart'; | 5 import 'package:csslib/visitor.dart'; |
6 | 6 |
| 7 const _default = const css.PreprocessorOptions( |
| 8 useColors: false, |
| 9 checked: true, |
| 10 warningsAsErrors: true, |
| 11 inputFile: 'memory'); |
| 12 |
7 /** | 13 /** |
8 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, | 14 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
9 * CSS will allow any property/value pairs regardless of validity; all of our | 15 * CSS will allow any property/value pairs regardless of validity; all of our |
10 * tests (by default) will ensure that the CSS is really valid. | 16 * tests (by default) will ensure that the CSS is really valid. |
11 */ | 17 */ |
12 StyleSheet parseCss(String cssInput, {List errors, List opts}) => css.parse( | 18 StyleSheet parseCss(String cssInput, |
13 cssInput, | 19 {List errors, css.PreprocessorOptions opts}) { |
14 errors: errors, | 20 return css.parse(cssInput, |
15 options: opts == null | 21 errors: errors, options: opts == null ? _default : opts); |
16 ? ['--no-colors', '--checked', '--warnings_as_errors', 'memory'] | 22 } |
17 : opts); | |
18 | 23 |
19 // Pretty printer for CSS. | 24 // Pretty printer for CSS. |
20 var emitCss = new CssPrinter(); | 25 var emitCss = new CssPrinter(); |
21 String prettyPrint(StyleSheet ss) => | 26 String prettyPrint(StyleSheet ss) => |
22 (emitCss..visitTree(ss, pretty: true)).toString(); | 27 (emitCss..visitTree(ss, pretty: true)).toString(); |
23 | 28 |
24 main() { | 29 main() { |
25 var errors = []; | 30 var errors = []; |
26 | 31 |
27 // Parse a simple stylesheet. | 32 // Parse a simple stylesheet. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 var selectorAst = css.selector('#div .foo', errors: errors); | 87 var selectorAst = css.selector('#div .foo', errors: errors); |
83 if (!errors.isEmpty) { | 88 if (!errors.isEmpty) { |
84 print("Got ${errors.length} errors.\n"); | 89 print("Got ${errors.length} errors.\n"); |
85 for (var error in errors) { | 90 for (var error in errors) { |
86 print(error); | 91 print(error); |
87 } | 92 } |
88 } else { | 93 } else { |
89 print(prettyPrint(selectorAst)); | 94 print(prettyPrint(selectorAst)); |
90 } | 95 } |
91 } | 96 } |
OLD | NEW |