Skip to content

Commit 7ba6695

Browse files
MoOxromainmenke
authored andcommitted
Added: lineBreak option
Ref: postcss/postcss-selector-matches#1
1 parent dec788d commit 7ba6695

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

plugins/postcss-selector-not/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.1.0 - 2015-06-13
2+
3+
- Added: `lineBreak` option
4+
15
# 1.0.2 - 2015-06-13
26

37
- Fixed: support of pseudo classes that use parenthesis

plugins/postcss-selector-not/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ p:not(:first-child), p:not(.special) {
3737
}
3838
```
3939

40+
## Options
41+
42+
### `lineBreak`
43+
44+
(default: `false`)
45+
46+
Allows you to introduce a line break between generated selectors.
47+
4048
---
4149

4250
## [Changelog](CHANGELOG.md)

plugins/postcss-selector-not/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-selector-not",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "PostCSS plugin to transform :not() W3C CSS leve 4 pseudo class to :not() CSS level 3 selectors",
55
"keywords": [
66
"postcss",

plugins/postcss-selector-not/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ function explodeSelector(pseudoClass, selector) {
2626
}
2727

2828
function explodeSelectors(pseudoClass) {
29-
return () => {
29+
return (options = {}) => {
3030
return (css) => {
3131
css.eachRule(rule => {
3232
if (rule.selector && rule.selector.indexOf(pseudoClass) > -1) {
33-
rule.selector = explodeSelector(pseudoClass, rule.selector).join(", ")
33+
rule.selector = explodeSelector(pseudoClass, rule.selector)
34+
.join("," + (options.lineBreak ? "\n" + rule.before : " "))
3435
}
3536
})
3637
}
3738
}
3839
}
3940

41+
4042
export default postcss.plugin("postcss-selector-not", explodeSelectors(":not"))

plugins/postcss-selector-not/test/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import tape from "tape"
33
import postcss from "postcss"
44
import selectorNot from "../src/index.js"
55

6-
function transform(css) {
7-
return postcss(selectorNot).process(css).css
6+
function transform(css, options = {}) {
7+
return postcss(selectorNot(options)).process(css).css
88
}
99

1010
tape("postcss-selector-not", t => {
@@ -56,5 +56,26 @@ tape("postcss-selector-not", t => {
5656
"should transform childs with parenthesis"
5757
)
5858

59+
t.equal(
60+
transform(`a:not(
61+
.b,
62+
.c
63+
) {}`),
64+
"a:not(.b), a:not(.c) {}",
65+
"should works with lots of whitespace"
66+
)
67+
68+
t.equal(
69+
transform(".foo:not(:nth-child(-n+2), .bar) {}", {lineBreak: true}),
70+
".foo:not(:nth-child(-n+2)),\n.foo:not(.bar) {}",
71+
"should add line break if asked too"
72+
)
73+
74+
t.equal(
75+
transform(" .foo:not(:nth-child(-n+2), .bar) {}", {lineBreak: true}),
76+
" .foo:not(:nth-child(-n+2)),\n .foo:not(.bar) {}",
77+
"should add line break if asked too, and respect indentation"
78+
)
79+
5980
t.end()
6081
})

0 commit comments

Comments
 (0)