Skip to content

Commit 0a7be25

Browse files
committed
Initial commit
0 parents  commit 0a7be25

39 files changed

+1348
-0
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎.npmignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
support
2+
test
3+
examples
4+
*.sock

‎History.md‎

Whitespace-only changes.

‎Makefile‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
test:
3+
@./node_modules/.bin/mocha \
4+
--require should \
5+
--reporter spec
6+
7+
.PHONY: test

‎Readme.md‎

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
2+
# rework
3+
4+
CSS manipulations built on [node-css](github.com/visionmedia/node-css),
5+
allowing you to automate vendor prefixing, create your own properties,
6+
inline images, anything you can imagine!
7+
8+
## API
9+
10+
### rework(css)
11+
12+
Return a new `Rework` instance for the given string of `css`.
13+
14+
### Rework#vendors(prefixes)
15+
16+
Define vendor `prefixes` that plugins may utilize,
17+
however most plugins do and should accept direct passing
18+
of vendor prefixes as well.
19+
20+
### Rework#use(fn)
21+
22+
Use the given plugin `fn`. A rework "plugin" is simply
23+
a function accepting the stylesheet object and `Rework` instance,
24+
view the definitions in `./lib/plugins` for examples.
25+
26+
### Rework#toString()
27+
28+
Return the string representation of the manipulated css.
29+
30+
## Plugins
31+
32+
The following plugins are bundled with `rework`:
33+
34+
### .at2x([vendors])
35+
36+
Add retina support for images, with optional `vendor` prefixes,
37+
defaulting to `.vendors()`.
38+
39+
```css
40+
logo {
41+
background-image: url('/public/images/logo.png')
42+
}
43+
```
44+
45+
yields:
46+
47+
```css
48+
logo {
49+
background-image: url('/public/images/logo.png')
50+
}
51+
52+
@media all and (-webkit-min-device-pixel-ratio : 1.5) {
53+
.logo {
54+
background-image: url("/public/images/logo@2x.png")
55+
}
56+
}
57+
```
58+
59+
### .prefix(property, [vendors])
60+
61+
Prefix `property` with optional `vendors` defaulting to `.vendors()`.
62+
63+
```css
64+
.button {
65+
border-radius: 5px;
66+
}
67+
```
68+
69+
yields:
70+
71+
```css
72+
.button {
73+
-webkit-border-radius: 5px;
74+
-moz-border-radius: 5px;
75+
border-radius: 5px;
76+
}
77+
```
78+
79+
### .prefixValue(value, [vendors])
80+
81+
Prefix `value` with optional `vendors` defaulting to `.vendors()`.
82+
83+
```css
84+
button {
85+
transition: height, transform 2s, width 0.3s linear;
86+
}
87+
```
88+
89+
yields:
90+
91+
```css
92+
button {
93+
-webkit-transition: height, -webkit-transform 2s, width 0.3s linear;
94+
-moz-transition: height, -moz-transform 2s, width 0.3s linear;
95+
transition: height, transform 2s, width 0.3s linear
96+
}
97+
```
98+
99+
### .opacity()
100+
101+
Add IE opacity support.
102+
103+
```css
104+
ul {
105+
opacity: 1 !important;
106+
}
107+
```
108+
109+
yields:
110+
111+
```css
112+
ul {
113+
opacity: 1 !important;
114+
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100) !important;
115+
filter: alpha(opacity=100) !important
116+
}
117+
```
118+
119+
### .keyframes([vendors])
120+
121+
Prefix __@keyframes__ with `vendors` defaulting to `.vendors()`.
122+
Ordering with `.keyframes()` is important, as other plugins
123+
may traverse into the newly generated rules, for example the
124+
following will allow `.prefix()` to prefix keyframe `border-radius`
125+
property, `.prefix()` is also smart about which keyframes definition
126+
it is within, and will not add extraneous vendor definitions.
127+
128+
```js
129+
var css = rework(read('examples/keyframes.css', 'utf8'))
130+
.vendors(['-webkit-', '-moz-'])
131+
.use(rework.keyframes())
132+
.use(rework.prefix('border-radius'))
133+
.toString()
134+
```
135+
136+
```css
137+
@keyframes animation {
138+
from {
139+
opacity: 0;
140+
}
141+
142+
to {
143+
opacity: 1;
144+
}
145+
}
146+
```
147+
148+
yields:
149+
150+
```css
151+
@keyframes animation {
152+
from {
153+
opacity: 0;
154+
}
155+
156+
to {
157+
opacity: 1;
158+
}
159+
}
160+
161+
@-webkit-keyframes animation {
162+
from {
163+
opacity: 0;
164+
}
165+
166+
to {
167+
opacity: 1;
168+
}
169+
}
170+
```
171+
172+
## Example
173+
174+
example.js:
175+
176+
```js
177+
var rework = require('rework')
178+
, read = require('fs').readFileSync
179+
, str = read('example.css', 'utf8');
180+
181+
var css = rework(str)
182+
.vendors(['-webkit-', '-moz-'])
183+
.use(rework.keyframes())
184+
.use(rework.prefix('border-radius'))
185+
.toString()
186+
187+
console.log(css);
188+
```
189+
190+
example.css:
191+
192+
```css
193+
@keyframes animation {
194+
from { opacity: 0; border-radius: 5px }
195+
to { opacity: 1; border-radius: 5px }
196+
}
197+
```
198+
199+
stdout:
200+
201+
```css
202+
@keyframes animation {
203+
from {
204+
opacity: 0;
205+
border-radius: 5px
206+
}
207+
208+
to {
209+
opacity: 1;
210+
border-radius: 5px
211+
}
212+
}
213+
214+
@-webkit-keyframes animation {
215+
from {
216+
opacity: 0;
217+
-webkit-border-radius: 5px;
218+
border-radius: 5px
219+
}
220+
221+
to {
222+
opacity: 1;
223+
-webkit-border-radius: 5px;
224+
border-radius: 5px
225+
}
226+
}
227+
228+
@-moz-keyframes animation {
229+
from {
230+
opacity: 0;
231+
-moz-border-radius: 5px;
232+
border-radius: 5px
233+
}
234+
235+
to {
236+
opacity: 1;
237+
-moz-border-radius: 5px;
238+
border-radius: 5px
239+
}
240+
}
241+
```
242+
243+
## License
244+
245+
(The MIT License)
246+
247+
Copyright (c) 2012 Learnboost <tj@vision-media.ca>
248+
249+
Permission is hereby granted, free of charge, to any person obtaining
250+
a copy of this software and associated documentation files (the
251+
'Software'), to deal in the Software without restriction, including
252+
without limitation the rights to use, copy, modify, merge, publish,
253+
distribute, sublicense, and/or sell copies of the Software, and to
254+
permit persons to whom the Software is furnished to do so, subject to
255+
the following conditions:
256+
257+
The above copyright notice and this permission notice shall be
258+
included in all copies or substantial portions of the Software.
259+
260+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
261+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
262+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
263+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
264+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
265+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
266+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎examples/at2x.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.logo {
2+
background-image: url('/public/images/logo.png');
3+
}

‎examples/at2x.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
var rework = require('..')
3+
, read = require('fs').readFileSync;
4+
5+
var css = rework(read('examples/at2x.css', 'utf8'))
6+
.vendors(['-webkit-', '-moz-'])
7+
.use(rework.at2x())
8+
.toString()
9+
10+
console.log(css);

‎examples/keyframes.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@keyframes animation {
2+
from { opacity: 0; border-radius: 5px }
3+
to { opacity: 1; border-radius: 5px }
4+
}

‎examples/keyframes.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
var rework = require('..')
3+
, read = require('fs').readFileSync;
4+
5+
var css = rework(read('examples/keyframes.css', 'utf8'))
6+
.vendors(['-webkit-', '-moz-', '-ms-'])
7+
.use(rework.keyframes())
8+
.use(rework.opacity())
9+
.use(rework.prefix('border-radius'))
10+
.toString()
11+
12+
console.log(css);

‎examples/opacity.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
a {
3+
opacity: .5;
4+
}
5+
6+
ul {
7+
opacity: 1 !important;
8+
}

0 commit comments

Comments
 (0)