Skip to content

Commit 52eaefc

Browse files
committed
illustrations and license
1 parent f7f5240 commit 52eaefc

File tree

6 files changed

+117
-4
lines changed

6 files changed

+117
-4
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2012 Joe Nelson.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
![Logo](css-ratiocinator/raw/master/illustration/githubheader.png "Logo")
22

33
The CSS Ratiocinator automatically refactors your CSS and generates a
4-
new stylesheet for your site. It works by examining your site's live
5-
DOM in the browser and reverse engineering a new, more elegant, CSS
6-
definition that captures styles down to the pixel.
4+
new stylesheet for your site. It works by examining your site's live DOM
5+
in the browser and reverse engineering a new, more elegant definition
6+
that captures styles down to the pixel.
77

88
It addresses the problem of old CSS whose styles accumulate and
99
contradict each other. After a certain point all CSS seems to grow only
10-
by internal antagonism. The ratiocinator wipes the slate clean and
10+
by internal antagonism. The Ratiocinator wipes the slate clean and
1111
provides a harmonious new beginning.
1212

1313
## Usage
@@ -24,3 +24,33 @@ Runs best in [Google Chrome](//www.google.com/chrome).
2424

2525
## Mechanism
2626

27+
The ratiocinator proceeds in two phases: assessment and consolidation.
28+
During assessment it determines which nodes will need which styles,
29+
accounting for browser defaults and cascade rules. The browser provides
30+
a full list of computed style for every node, and our first step is to
31+
prune redundencies from cascaded style in a depth-first process called
32+
"lifting." ![Lifting](css-ratiocinator/raw/master/illustration/lift.png "Lifting")
33+
34+
The last step in assessment is stripping default styles. The final
35+
style needn't specify CSS defaults, so we remove them prior to the
36+
consolidation phase.
37+
38+
Next comes consolidation, where we find shared pieces of style
39+
throughout the cleaned DOM tree and extract them to CSS declarations.
40+
41+
![Consolidating](css-ratiocinator/raw/master/illustration/consolidate.png "Consolidating")
42+
43+
In the diagram above, the ratiocinator will choose to output a
44+
declaration for the styles in red before those in blue. Although there
45+
are more blue items than red in element `aside.foo`, there are more red
46+
elements overall. The red has greater "volume." Hence the ratiocinator
47+
will extract styles for all elements with class `foo` first and then for
48+
`aside` elements second.
49+
50+
## Contributing
51+
52+
## License
53+
54+
The CSS Ratiocinator is Copyright © 2012 Joe Nelson. It is free
55+
software, and may be redistributed under the terms specified in the
56+
LICENSE file.

illustration/consolidate.dot

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
digraph G {
2+
rankdir=LR
3+
node [shape=record];
4+
5+
subgraph cluster_dom {
6+
label="Consolidating";
7+
color=lightgrey;
8+
body [label="body"];
9+
div [label=<
10+
<table border="0">
11+
<tr><td>div.foo</td></tr>
12+
<tr><td><FONT color="red">color: black</FONT></td></tr>
13+
<tr><td><FONT color="red">margin: 10px</FONT></td></tr>
14+
</table>
15+
>]
16+
aside [label=<
17+
<table border="0">
18+
<tr><td>aside.foo</td></tr>
19+
<tr><td><FONT color="red">color: black</FONT></td></tr>
20+
<tr><td><FONT color="blue">background: #AAA</FONT></td></tr>
21+
<tr><td><FONT color="blue">border: 1px solid black</FONT></td></tr>
22+
<tr><td><FONT color="blue">border-radius: 5px</FONT></td></tr>
23+
<tr><td><FONT color="red">margin: 10px</FONT></td></tr>
24+
</table>
25+
>]
26+
27+
body -> div;
28+
body -> aside;
29+
}
30+
}

illustration/consolidate.png

26.3 KB
Loading

illustration/lift.dot

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
digraph G {
2+
rankdir=LR
3+
node [shape=record];
4+
5+
subgraph cluster_after {
6+
rank=2;
7+
label="After";
8+
color=lightgrey;
9+
body_1 [label="body"];
10+
div_1 [label="div | color: red"];
11+
p_10 [label="p | font-weight: bold"];
12+
p_11 [label="p"];
13+
14+
body_1 -> div_1;
15+
div_1 -> p_10;
16+
div_1 -> p_11;
17+
}
18+
19+
subgraph cluster_before {
20+
rank=1;
21+
label="Before";
22+
color=lightgrey;
23+
body_0 [label="body"];
24+
div_0 [label="div | color: red"];
25+
p_00 [label="p | color: red | font-weight: bold"];
26+
p_01 [label="p | color: red"];
27+
28+
body_0 -> div_0;
29+
div_0 -> p_00;
30+
div_0 -> p_01;
31+
}
32+
}

illustration/lift.png

27.8 KB
Loading

0 commit comments

Comments
 (0)