postcss 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of postcss might be problematic. Click here for more details.
- package/ChangeLog.md +4 -0
- package/README.md +57 -5
- package/lib/map-generator.js +3 -3
- package/lib/parse.js +3 -3
- package/lib/postcss.js +4 -2
- package/lib/result.js +5 -1
- package/package.json +5 -5
package/ChangeLog.md
CHANGED
package/README.md
CHANGED
@@ -26,10 +26,19 @@ Sponsored by [Evil Martians](http://evilmartians.com/).
|
|
26
26
|
* [Autoprefixer] adds vendor prefixes by Can I Use data.
|
27
27
|
* [grunt-pixrem], `rem` unit polyfill.
|
28
28
|
* [CSS MQPacker] joins same media queries.
|
29
|
-
|
30
|
-
[
|
31
|
-
[
|
32
|
-
[
|
29
|
+
* [RTLCSS] mirrors styles for right-to-left locales.
|
30
|
+
* [CSSWring] and [grunt-csswring] CSS minifier with full source map support.
|
31
|
+
* [Grunt-webpcss] to duplicate images in CSS to WebP for supported browsers.
|
32
|
+
* [Pleeease] is a pack of various postprocessors.
|
33
|
+
|
34
|
+
[grunt-csswring]: https://github.com/princed/grunt-csswring
|
35
|
+
[Grunt-webpcss]: https://github.com/lexich/grunt-webpcss
|
36
|
+
[Autoprefixer]: https://github.com/ai/autoprefixer
|
37
|
+
[grunt-pixrem]: https://github.com/robwierzbowski/grunt-pixrem
|
38
|
+
[CSS MQPacker]: https://github.com/hail2u/node-css-mqpacker
|
39
|
+
[Pleeease]: http://pleeease.io/
|
40
|
+
[CSSWring]: https://github.com/hail2u/node-csswring
|
41
|
+
[RTLCSS]: https://github.com/MohammadYounes/rtlcss
|
33
42
|
|
34
43
|
## Quick Example
|
35
44
|
|
@@ -183,6 +192,39 @@ Because of this background difference, PostCSS:
|
|
183
192
|
|
184
193
|
## Usage
|
185
194
|
|
195
|
+
You can parse CSS by `postcss.parse()` method, which returns CSS AST:
|
196
|
+
|
197
|
+
```js
|
198
|
+
var postcss = require('postcss');
|
199
|
+
|
200
|
+
var css = postcss.parse('a { color: black }');
|
201
|
+
```
|
202
|
+
|
203
|
+
Then you can change this AST. Use `css.list` to get childs.
|
204
|
+
Properties `rule.selector`, `decl.prop`, `decl.value`, `atrule.name`
|
205
|
+
and `atrule.params` contain data.
|
206
|
+
|
207
|
+
Don’t use underscore properties (like `_selector`, `_params` and `_value`),
|
208
|
+
because they are only for comments save magic
|
209
|
+
(See [Raw Properties](#Raw Properties) below). Use getters and setters instead
|
210
|
+
(like `selector`, `selectors`, `params` and `value`).
|
211
|
+
|
212
|
+
```js
|
213
|
+
css.list[0].value = 'white';
|
214
|
+
```
|
215
|
+
|
216
|
+
After changes you can get new CSS and modification’s source map:
|
217
|
+
|
218
|
+
```js
|
219
|
+
var result = css.toResult(options);
|
220
|
+
|
221
|
+
result.css //=> 'a { color: white }'
|
222
|
+
result.map //=> '{"version":3, … }'
|
223
|
+
```
|
224
|
+
|
225
|
+
Methods `postcss.parse()` and `CSS#toResult()` are low level API, for most cases
|
226
|
+
it will be better to create processors with simplier API and chaining.
|
227
|
+
|
186
228
|
### Processor
|
187
229
|
|
188
230
|
The function `postcss(fn)` creates a processor from your function:
|
@@ -247,6 +289,14 @@ processor.process(wrong, { from: 'main.css' });
|
|
247
289
|
//=> Can't parse CSS: Unclosed block at line 1:1 in main.css
|
248
290
|
```
|
249
291
|
|
292
|
+
You can also use result from previous postprocessor or already parsed `Root`
|
293
|
+
as argument in next one:
|
294
|
+
|
295
|
+
```js
|
296
|
+
result = processor1.process(css)
|
297
|
+
processor2.process(result)
|
298
|
+
```
|
299
|
+
|
250
300
|
### Multiple Inputs
|
251
301
|
|
252
302
|
The function `postcss()` generates processor only for one input.
|
@@ -566,7 +616,7 @@ Because CSS have nested structure, PostCSS also contains recursive iterator
|
|
566
616
|
|
567
617
|
```js
|
568
618
|
root.eachInside(function (node, i) {
|
569
|
-
console.log(node.type ' inside ' + parent.type);
|
619
|
+
console.log(node.type + ' inside ' + node.parent.type);
|
570
620
|
});
|
571
621
|
```
|
572
622
|
|
@@ -590,6 +640,8 @@ root.eachComment(function (comment, i) {
|
|
590
640
|
})
|
591
641
|
```
|
592
642
|
|
643
|
+
You can break iteration by `return false`.
|
644
|
+
|
593
645
|
### Root Node
|
594
646
|
|
595
647
|
`Root` node contains entire CSS tree. Its children can be only `Comment`,
|
package/lib/map-generator.js
CHANGED
@@ -153,9 +153,9 @@
|
|
153
153
|
this.applyPrevMap();
|
154
154
|
this.addAnnotation();
|
155
155
|
if (this.isInline()) {
|
156
|
-
return new Result(this.css);
|
156
|
+
return new Result(this.root, this.css);
|
157
157
|
} else {
|
158
|
-
return new Result(this.css, this.map.toString());
|
158
|
+
return new Result(this.root, this.css, this.map.toString());
|
159
159
|
}
|
160
160
|
};
|
161
161
|
|
@@ -229,7 +229,7 @@
|
|
229
229
|
if (this.isMap()) {
|
230
230
|
return this.generateMap();
|
231
231
|
} else {
|
232
|
-
return new Result(this.root
|
232
|
+
return new Result(this.root);
|
233
233
|
}
|
234
234
|
};
|
235
235
|
|
package/lib/parse.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
(function() {
|
2
|
-
var AtRule, Comment, Declaration, Parser, Raw, Root, Rule,
|
2
|
+
var AtRule, Comment, Declaration, Parser, Raw, Root, Rule, SyntaxError;
|
3
3
|
|
4
|
-
|
4
|
+
SyntaxError = require('./syntax-error');
|
5
5
|
|
6
6
|
Declaration = require('./declaration');
|
7
7
|
|
@@ -316,7 +316,7 @@
|
|
316
316
|
column: this.column
|
317
317
|
};
|
318
318
|
}
|
319
|
-
throw new
|
319
|
+
throw new SyntaxError(message, this.source, position, this.opts.from);
|
320
320
|
};
|
321
321
|
|
322
322
|
Parser.prototype.move = function() {
|
package/lib/postcss.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
(function() {
|
2
|
-
var AtRule, Comment, Declaration, PostCSS, Root, Rule, postcss,
|
2
|
+
var AtRule, Comment, Declaration, PostCSS, Result, Root, Rule, postcss,
|
3
3
|
__slice = [].slice;
|
4
4
|
|
5
5
|
Declaration = require('./declaration');
|
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
AtRule = require('./at-rule');
|
10
10
|
|
11
|
+
Result = require('./result');
|
12
|
+
|
11
13
|
Rule = require('./rule');
|
12
14
|
|
13
15
|
Root = require('./root');
|
@@ -27,7 +29,7 @@
|
|
27
29
|
if (opts == null) {
|
28
30
|
opts = {};
|
29
31
|
}
|
30
|
-
parsed = postcss.parse(css, opts);
|
32
|
+
parsed = css instanceof Root ? css : css instanceof Result ? parsed = css.root : postcss.parse(css, opts);
|
31
33
|
_ref = this.processors;
|
32
34
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
33
35
|
processor = _ref[_i];
|
package/lib/result.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "postcss",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.5",
|
4
4
|
"description": "Framework for CSS postprocessors",
|
5
5
|
"keywords": ["css", "parser", "postproccessor"],
|
6
6
|
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
@@ -15,11 +15,11 @@
|
|
15
15
|
},
|
16
16
|
"devDependencies": {
|
17
17
|
"coffee-script": "1.7.1",
|
18
|
-
"fs-extra": "0.
|
18
|
+
"fs-extra": "0.9.1",
|
19
19
|
"gonzales": "1.0.7",
|
20
|
-
"rework": "0.20.
|
21
|
-
"should": "
|
22
|
-
"mocha": "1.
|
20
|
+
"rework": "0.20.3",
|
21
|
+
"should": "4.0.0",
|
22
|
+
"mocha": "1.20.0",
|
23
23
|
"cssom": "0.3.0"
|
24
24
|
},
|
25
25
|
"main": "lib/postcss",
|