| 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( | 7 const _default = const css.PreprocessorOptions( |
| 8 useColors: false, | 8 useColors: false, |
| 9 checked: true, | 9 checked: true, |
| 10 warningsAsErrors: true, | 10 warningsAsErrors: true, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 '@import "support/at-charset-019.css"; div { color: red; }' | 36 '@import "support/at-charset-019.css"; div { color: red; }' |
| 37 'button[type] { background-color: red; }' | 37 'button[type] { background-color: red; }' |
| 38 '.foo { ' | 38 '.foo { ' |
| 39 'color: red; left: 20px; top: 20px; width: 100px; height:200px' | 39 'color: red; left: 20px; top: 20px; width: 100px; height:200px' |
| 40 '}' | 40 '}' |
| 41 '#div {' | 41 '#div {' |
| 42 'color : #00F578; border-color: #878787;' | 42 'color : #00F578; border-color: #878787;' |
| 43 '}', | 43 '}', |
| 44 errors: errors); | 44 errors: errors); |
| 45 | 45 |
| 46 if (!errors.isEmpty) { | 46 if (errors.isNotEmpty) { |
| 47 print("Got ${errors.length} errors.\n"); | 47 print("Got ${errors.length} errors.\n"); |
| 48 for (var error in errors) { | 48 for (var error in errors) { |
| 49 print(error); | 49 print(error); |
| 50 } | 50 } |
| 51 } else { | 51 } else { |
| 52 print(prettyPrint(stylesheet)); | 52 print(prettyPrint(stylesheet)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Parse a stylesheet with errors | 55 // Parse a stylesheet with errors |
| 56 print('2. Catch severe syntax errors:'); | 56 print('2. Catch severe syntax errors:'); |
| 57 print(' ==========================='); | 57 print(' ==========================='); |
| 58 var stylesheetError = parseCss( | 58 var stylesheetError = parseCss( |
| 59 '.foo #%^&*asdf{ ' | 59 '.foo #%^&*asdf{ ' |
| 60 'color: red; left: 20px; top: 20px; width: 100px; height:200px' | 60 'color: red; left: 20px; top: 20px; width: 100px; height:200px' |
| 61 '}', | 61 '}', |
| 62 errors: errors); | 62 errors: errors); |
| 63 | 63 |
| 64 if (!errors.isEmpty) { | 64 if (errors.isNotEmpty) { |
| 65 print("Got ${errors.length} errors.\n"); | 65 print("Got ${errors.length} errors.\n"); |
| 66 for (var error in errors) { | 66 for (var error in errors) { |
| 67 print(error); | 67 print(error); |
| 68 } | 68 } |
| 69 } else { | 69 } else { |
| 70 print(stylesheetError.toString()); | 70 print(stylesheetError.toString()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Parse a stylesheet that warns (checks) problematic CSS. | 73 // Parse a stylesheet that warns (checks) problematic CSS. |
| 74 print('3. Detect CSS problem with checking on:'); | 74 print('3. Detect CSS problem with checking on:'); |
| 75 print(' ==================================='); | 75 print(' ==================================='); |
| 76 stylesheetError = parseCss('# div1 { color: red; }', errors: errors); | 76 stylesheetError = parseCss('# div1 { color: red; }', errors: errors); |
| 77 | 77 |
| 78 if (!errors.isEmpty) { | 78 if (errors.isNotEmpty) { |
| 79 print("Detected ${errors.length} problem in checked mode.\n"); | 79 print("Detected ${errors.length} problem in checked mode.\n"); |
| 80 for (var error in errors) { | 80 for (var error in errors) { |
| 81 print(error); | 81 print(error); |
| 82 } | 82 } |
| 83 } else { | 83 } else { |
| 84 print(stylesheetError.toString()); | 84 print(stylesheetError.toString()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Parse a CSS selector. | 87 // Parse a CSS selector. |
| 88 print('4. Parse a selector only:'); | 88 print('4. Parse a selector only:'); |
| 89 print(' ======================'); | 89 print(' ======================'); |
| 90 var selectorAst = css.selector('#div .foo', errors: errors); | 90 var selectorAst = css.selector('#div .foo', errors: errors); |
| 91 if (!errors.isEmpty) { | 91 if (errors.isNotEmpty) { |
| 92 print("Got ${errors.length} errors.\n"); | 92 print("Got ${errors.length} errors.\n"); |
| 93 for (var error in errors) { | 93 for (var error in errors) { |
| 94 print(error); | 94 print(error); |
| 95 } | 95 } |
| 96 } else { | 96 } else { |
| 97 print(prettyPrint(selectorAst)); | 97 print(prettyPrint(selectorAst)); |
| 98 } | 98 } |
| 99 } | 99 } |
| OLD | NEW |