Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 92 lines (70 sloc) 3.17 kb
4cb2e7e Update readme file.
Øyvind Håkestad authored
1 ## uCSS library
696c780 Update help text, update readme.
Øyvind Håkestad authored
2 Find unused CSS, as well as duplicate CSS. Also, you can get an overview of how many times each rule has been used in your markup.
4cb2e7e Update readme file.
Øyvind Håkestad authored
3
4 Key features:
696c780 Update help text, update readme.
Øyvind Håkestad authored
5 * Find unused CSS selectors in a HTML code base.
6 * See how many times each CSS selector has been used.
7 * Find duplicate CSS selectors.
4cb2e7e Update readme file.
Øyvind Håkestad authored
8
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
9 But wait, there's more! By creating setting up a config file, uCSS can also:
696c780 Update help text, update readme.
Øyvind Håkestad authored
10 * Visit several URLs/HTML files in one go.
11 * Use several CSS files at once.
12 * Do login, and visit all pages both as a logged in and logged out user.
13 * Whitelist CSS rules that should be ignored.
4cb2e7e Update readme file.
Øyvind Håkestad authored
14
15 The library is written for Node (http://www.nodejs.org/). However, it should be easy to use it in other contexts as well.
16
17 uCSS can also be used as a command line tool.
18
19 ### Installation
20
21 `npm install ucss`
22
23 ### Usage (command line)
24
25 ```
26 $ ucss --help
27 Usage: ucss [OPTION]...
28
29 Options:
30 --help This help text.
31 --html, -h HTML to load.
32 --css, -c CSS to load.
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
33 --config, -g Config file to use. [default: true]
4cb2e7e Update readme file.
Øyvind Håkestad authored
34 --used, -u Show numbers on used rules, in addition to unused rules. [default: false]
35 --nosummary, -n Output summary. [default: false]
36 --duplicates, -d Show duplicates. [default: false]
37
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
38 Either a config file, or HTML and CSS files are required. If no arguments are specified, uCSS will look for a ucss.json file in the current directory.
4cb2e7e Update readme file.
Øyvind Håkestad authored
39 ```
40
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
41 For examples on writing a config file, please see the examples folder.
4cb2e7e Update readme file.
Øyvind Håkestad authored
42
43 ### Usage (as library)
44
45 ```
46 var css = ".foo {} .bar {} .baz {}";
47 var html = "<html><head></head><body class='foo'></body></html>";
48 var whitelist = [".baz"];
49 var auth = null;
50 ucss.analyze(css, html, whitelist, auth, function(result) {
51 require('../lib/helpers/output').standard(
696c780 Update help text, update readme.
Øyvind Håkestad authored
52 result, false, false, false);
4cb2e7e Update readme file.
Øyvind Håkestad authored
53 };);
54 ```
55
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
56 ### Setting up a config file
5faf559 More text
Øyvind Håkestad authored
57
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
58 If you want to do more fancy stuff than visiting one URL/file at a time, you can specify a config file.
5faf559 More text
Øyvind Håkestad authored
59
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
60 A config file will let you visit several URLs/files in one go, as well as fetch CSS from several files. You can also perform login, and white list rules. See the examples folder for an example config file.
4cb2e7e Update readme file.
Øyvind Håkestad authored
61
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
62 You can specify several config files, either one for each of your projects, or several for one project.
63 #### Logging in
64 Login requires you to set up a config file. In the config file, you can specify your own login function:
696c780 Update help text, update readme.
Øyvind Håkestad authored
65
66 ```
67 {
68 ...,
69 auth: {
70 "username": "foo",
71 "password": "bar",
72 "loginUrl": "http://example.com/login/",
73 "loginFunc": function(url, username, password, callback) {
74 // Do login, get cookie
75 var cookie = "sessionid:1234"
76 callback(cookie);
77 }
78 },
79 ...
80 }
81
82 ```
83 ...or you can just specify a login helper:
84
85 ```
fa67408 Typo
Øyvind Håkestad authored
86 "loginFunc": "djangoLogin"
696c780 Update help text, update readme.
Øyvind Håkestad authored
87 ```
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
88 There is currently only one login helper available, for Django.
4cb2e7e Update readme file.
Øyvind Håkestad authored
89
90 ### Custom output
91
d3b259e Change rename 'spec' to 'config'.
Øyvind Håkestad authored
92 If you use uCSS as a library, you can specify a custom output function.
Something went wrong with that request. Please try again.