OLD | NEW |
1 csslib in Pure Dart | 1 CSS parser library for Dart |
2 =================== | 2 ========================== |
3 | 3 |
4 This is a pure [Dart][dart] [CSS parser][cssparse]. Since it's 100% | 4 This is a [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) parser written
entirely in [Dart][dart]. |
5 Dart you can use it safely from a script or server side app. | 5 It can be used in the client/server/command line. |
6 | 6 |
7 Installation | 7 This package is installed with [Pub][pub], see: |
8 ------------ | 8 [install instructions](https://pub.dartlang.org/packages/csslib#installing) |
9 | 9 for this package. |
10 Add this to your `pubspec.yaml` (or create it): | |
11 ```yaml | |
12 dependencies: | |
13 csslib: any | |
14 ``` | |
15 Then run the [Pub Package Manager][pub] (comes with the Dart SDK): | |
16 | |
17 pub install | |
18 | 10 |
19 Usage | 11 Usage |
20 ----- | 12 ----- |
21 | 13 |
22 Parsing CSS is easy! | 14 Parsing CSS is easy! |
23 ```dart | 15 ```dart |
24 import 'package:csslib/parser.dart' show parse; | 16 import 'package:csslib/parser.dart' show parse; |
25 import 'package:csslib/css.dart'; | 17 import 'package:csslib/css.dart'; |
26 | 18 |
27 main() { | 19 main() { |
28 var stylesheet = parse( | 20 var stylesheet = parse( |
29 '.foo { color: red; left: 20px; top: 20px; width: 100px; height:200px }'); | 21 '.foo { color: red; left: 20px; top: 20px; width: 100px; height:200px }'); |
30 print(stylesheet.toString()); | 22 print(stylesheet.toString()); |
31 } | 23 } |
32 ``` | 24 ``` |
33 | 25 |
34 You can pass a String or list of bytes to `parse`. | 26 You can pass a String or list of bytes to `parse`. |
35 | 27 |
36 | 28 |
37 Updating | |
38 -------- | |
39 | |
40 You can upgrade the library with: | |
41 | |
42 pub update | |
43 | |
44 Disclaimer: the APIs are not finished. Updating may break your code. If that | |
45 happens, you can check the | |
46 [commit log](https://github.com/dart-lang/csslib/commits/master), to figure | |
47 out what the change was. | |
48 | |
49 If you want to avoid breakage, you can also put the version constraint in your | |
50 `pubspec.yaml` in place of the word `any`. | |
51 | |
52 Running Tests | 29 Running Tests |
53 ------------- | 30 ------------- |
54 | 31 |
55 All tests (both canary and suite) should be passing. Canary are quick test | 32 Basic tests can be found in this repository: |
56 verifies that basic CSS is working. The suite tests are a comprehensive set of | |
57 ~11,000 tests. | |
58 | |
59 ```bash | 33 ```bash |
60 export DART_SDK=path/to/dart/sdk | 34 pub run test |
61 | |
62 # Make sure dependencies are installed | |
63 pub install | |
64 | |
65 # Run command both canary and the suite tests | |
66 test/run.sh | |
67 ``` | 35 ``` |
68 | 36 |
69 Run only the canary test: | 37 The full CSS test suite can be found in https://github.com/dart-lang/csslib-test
-suite |
70 | |
71 ```bash | 38 ```bash |
72 test/run.sh canary | 39 cd ../csslib-test-suite |
73 ``` | 40 ./run.sh |
74 | |
75 Run only the suite tests: | |
76 | |
77 ```bash | |
78 test/run.sh suite | |
79 ``` | 41 ``` |
80 | 42 |
81 [dart]: http://www.dartlang.org/ | 43 [dart]: http://www.dartlang.org/ |
82 [pub]: http://www.dartlang.org/docs/pub-package-manager/ | 44 [pub]: http://www.dartlang.org/docs/pub-package-manager/ |
OLD | NEW |