Comparing version 0.3.4 to 0.3.5
@@ -0,1 +1,5 @@ | ||
## 0.3.5 | ||
* Allow to use `Root` or `Result` as first argument in `process()`. | ||
* Save parsed AST to `Result#root`. | ||
## 0.3.4 | ||
@@ -2,0 +6,0 @@ * Better space symbol detect to read UTF-8 BOM correctly. |
@@ -156,5 +156,5 @@ (function() { | ||
if (this.isInline()) { | ||
return new Result(this.css); | ||
return new Result(this.root, this.css); | ||
} else { | ||
return new Result(this.css, this.map.toString()); | ||
return new Result(this.root, this.css, this.map.toString()); | ||
} | ||
@@ -233,3 +233,3 @@ }; | ||
} else { | ||
return new Result(this.root.toString()); | ||
return new Result(this.root); | ||
} | ||
@@ -236,0 +236,0 @@ }; |
(function() { | ||
var AtRule, Comment, Declaration, Parser, Raw, Root, Rule, SyntexError; | ||
var AtRule, Comment, Declaration, Parser, Raw, Root, Rule, SyntaxError; | ||
SyntexError = require('./syntax-error'); | ||
SyntaxError = require('./syntax-error'); | ||
@@ -319,3 +319,3 @@ Declaration = require('./declaration'); | ||
} | ||
throw new SyntexError(message, this.source, position, this.opts.from); | ||
throw new SyntaxError(message, this.source, position, this.opts.from); | ||
}; | ||
@@ -322,0 +322,0 @@ |
(function() { | ||
var AtRule, Comment, Declaration, PostCSS, Root, Rule, postcss, | ||
var AtRule, Comment, Declaration, PostCSS, Result, Root, Rule, postcss, | ||
__slice = [].slice; | ||
@@ -11,2 +11,4 @@ | ||
Result = require('./result'); | ||
Rule = require('./rule'); | ||
@@ -31,3 +33,3 @@ | ||
} | ||
parsed = postcss.parse(css, opts); | ||
parsed = css instanceof Root ? css : css instanceof Result ? parsed = css.root : postcss.parse(css, opts); | ||
_ref = this.processors; | ||
@@ -34,0 +36,0 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
@@ -5,4 +5,8 @@ (function() { | ||
Result = (function() { | ||
function Result(css, map) { | ||
function Result(root, css, map) { | ||
this.root = root; | ||
this.css = css; | ||
if (this.css == null) { | ||
this.css = this.root.toString(); | ||
} | ||
if (map) { | ||
@@ -9,0 +13,0 @@ this.map = map; |
{ | ||
"name": "postcss", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Framework for CSS postprocessors", | ||
@@ -18,7 +18,7 @@ "keywords": ["css", "parser", "postproccessor"], | ||
"coffee-script": "1.7.1", | ||
"fs-extra": "0.8.1", | ||
"fs-extra": "0.9.1", | ||
"gonzales": "1.0.7", | ||
"rework": "0.20.2", | ||
"should": "3.1.3", | ||
"mocha": "1.17.1", | ||
"rework": "0.20.3", | ||
"should": "4.0.0", | ||
"mocha": "1.20.0", | ||
"cssom": "0.3.0" | ||
@@ -25,0 +25,0 @@ }, |
@@ -29,6 +29,15 @@ # PostCSS | ||
* [CSS MQPacker] joins same media queries. | ||
* [RTLCSS] mirrors styles for right-to-left locales. | ||
* [CSSWring] and [grunt-csswring] CSS minifier with full source map support. | ||
* [Grunt-webpcss] to duplicate images in CSS to WebP for supported browsers. | ||
* [Pleeease] is a pack of various postprocessors. | ||
[Autoprefixer]: https://github.com/ai/autoprefixer | ||
[grunt-pixrem]: https://github.com/robwierzbowski/grunt-pixrem | ||
[CSS MQPacker]: https://github.com/hail2u/node-css-mqpacker | ||
[grunt-csswring]: https://github.com/princed/grunt-csswring | ||
[Grunt-webpcss]: https://github.com/lexich/grunt-webpcss | ||
[Autoprefixer]: https://github.com/ai/autoprefixer | ||
[grunt-pixrem]: https://github.com/robwierzbowski/grunt-pixrem | ||
[CSS MQPacker]: https://github.com/hail2u/node-css-mqpacker | ||
[Pleeease]: http://pleeease.io/ | ||
[CSSWring]: https://github.com/hail2u/node-csswring | ||
[RTLCSS]: https://github.com/MohammadYounes/rtlcss | ||
@@ -187,2 +196,35 @@ ## Quick Example | ||
You can parse CSS by `postcss.parse()` method, which returns CSS AST: | ||
```js | ||
var postcss = require('postcss'); | ||
var css = postcss.parse('a { color: black }'); | ||
``` | ||
Then you can change this AST. Use `css.list` to get childs. | ||
Properties `rule.selector`, `decl.prop`, `decl.value`, `atrule.name` | ||
and `atrule.params` contain data. | ||
Don’t use underscore properties (like `_selector`, `_params` and `_value`), | ||
because they are only for comments save magic | ||
(See [Raw Properties](#Raw Properties) below). Use getters and setters instead | ||
(like `selector`, `selectors`, `params` and `value`). | ||
```js | ||
css.list[0].value = 'white'; | ||
``` | ||
After changes you can get new CSS and modification’s source map: | ||
```js | ||
var result = css.toResult(options); | ||
result.css //=> 'a { color: white }' | ||
result.map //=> '{"version":3, … }' | ||
``` | ||
Methods `postcss.parse()` and `CSS#toResult()` are low level API, for most cases | ||
it will be better to create processors with simplier API and chaining. | ||
### Processor | ||
@@ -252,2 +294,10 @@ | ||
You can also use result from previous postprocessor or already parsed `Root` | ||
as argument in next one: | ||
```js | ||
result = processor1.process(css) | ||
processor2.process(result) | ||
``` | ||
### Multiple Inputs | ||
@@ -572,3 +622,3 @@ | ||
root.eachInside(function (node, i) { | ||
console.log(node.type ' inside ' + parent.type); | ||
console.log(node.type + ' inside ' + node.parent.type); | ||
}); | ||
@@ -597,2 +647,4 @@ ``` | ||
You can break iteration by `return false`. | ||
### Root Node | ||
@@ -599,0 +651,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73394
1587
785