/
CSS-refactorisation.html.hbs
132 lines (78 loc) · 2.45 KB
/
CSS-refactorisation.html.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/!\ WIP /!\
# CSS Refactorisation
## Convert to a pre-processor
`sass-convert` or [css2Sass](http://css2sass.heroku.com/)
### Explode the code into files
And use pre-processed `@import`
### Easy replacements with regex for better readability
#### Urls
##### Images
url\(('|")?(\.\.)?(\/)?(img|images)\/([^)'"]*)('|")?\)
image-url\("$5"\)
##### Fonts
url\(('|")?(\.\.)?(\/)?(fonts?)\/([^)'"]*)('|")?\)
font-url\("$5"\)
#### Replace &/or remove deprecated CSS 3 prefix if you can
Depending on you browser support. (check on [CanIUse.com](http://caniuse.com))
##### Box shadow
(-moz-|-webkit-)?box-shadow: ?([^;]+);\s+(-moz-|-webkit-)?box-shadow: ?([^;]+);\s+(-moz-|-webkit-)?box-shadow: ?([^;]+);
//depending on browser support
@include box-shadow($2);
or
box-shadow: $2;
##### Border-radius
(-moz-|-webkit-)?border-radius: ?([^;]+);\s+(-moz-|-webkit-)?border-radius: ?([^;]+);\s+(-moz-|-webkit-)?border-radius: ?([^;]+);
//depending on browser support
@include border-radius($2);
or
border-radius: $2;
#### Replace colors
#ffffff
#fff
\bwhite([^-]|;,) // to avoid white-space dude !
#fff$1
#000000
#000
\bblack([^-]|;,)
#000
// sass rgba
?0 ?, ?0 ?, ?0 ?, ?
#000,
?255 ?, ?255 ?, ?255 ?, ?
#fff,
#### Remove useless 0.x
( |,)0\.
$1.
##### Dead code
Search CSS classes in non style files (search where you want & add `,-*.css,-*.scss` in the scope "Where" in SublimeText)
### Look for redondantes parts
Use variables !
#### Colors
#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?
Then create a color files with var (Note: This can be long) using color functions of the pre-processor.
##### Colors Tools
* [coloratum](http://coloratum.com)
* [0to255](http://0to255.com/)
* [Color comparator](http://codepen.io/MoOx/full/Ctwzb)
#### Values
pixels, em & stuffs & create variables
#### Media queries
Create media queries breakpoints with em, & create some mixins
```scss
$media-width-large: 30em !default;
@mixin media-large() {
@media (min-width: $media-width-small) { @content }
}
//...
selector {
width: $small;
@include crp-Media-small() { width: $large }
}
```
#### Find multiples CSS properties...
...You know, copy pasted everywhere...
Then create base class + used `@extend` in your code.
## Start real refactoring
The previous step does not only make this CSS code more readable, but it has help you being familiar with it.
Now that you have a sort of readable code (I hope more than before), you can start real work.
###