Skip to content

Commit 8463e37

Browse files
committed
Merge pull request csstools#27 from postcss/fix.rewrite-matches
Fixed: Nested/mixed selectors now works correctly
2 parents 82b157d + cfa6e22 commit 8463e37

File tree

30 files changed

+507
-427
lines changed

30 files changed

+507
-427
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"stage": 0
3+
}

.eslintignore

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

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# babel support more syntax stuff than eslint for now
3+
parser: babel-eslint
4+
5+
ecmaFeatures:
6+
modules: true
7+
8+
env:
9+
es6: true
10+
browser: true
11+
node: true
12+
13+
rules:
14+
indent: [2, 2] # 2 spaces indentation
15+
max-len: [2, 80, 4]
16+
quotes: [2, "double"]
17+
semi: [2, "never"]
18+
no-multiple-empty-lines: [2, {"max": 1}]
19+
20+
brace-style: [2, "stroustrup"]
21+
comma-dangle: [2, "always-multiline"]
22+
comma-style: [2, "last"]
23+
computed-property-spacing: [2, "never"]
24+
dot-location: [2, "property"]
25+
26+
one-var: [2, "never"]
27+
#no-var: [2]
28+
prefer-const: [2]
29+
no-bitwise: [2]
30+
31+
object-shorthand: [2, "methods"]
32+
space-after-keywords: [2, "always"]
33+
space-before-blocks: [2, "always"]
34+
space-before-function-paren: [2, "never"]
35+
space-in-brackets: [2, "never"]
36+
space-in-parens: [2, "never"]
37+
spaced-line-comment: [2, "always"]

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
2-
node_modules
3-
test/fixtures/*/actual.css
42
*.sublime-workspace
53

4+
node_modules
5+
test/fixtures/*/actual.css
6+
dist

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# 2.2.0 - 2015-06-30 (By @MoOx)
1+
# 2.3.0 - 2015-07-14
2+
3+
* Fixed: Nested/mixed selectors now works correctly
4+
([#19](https://github.com/postcss/postcss-custom-selectors/issues/19))
5+
* Added: `transformMatches` option to limit transformation to :matches()
6+
replacements.
7+
8+
# 2.2.0 - 2015-06-30
29

310
* Fixed: No more useless warnings for undefined non custom selectors
411
([#22](https://github.com/postcss/postcss-custom-selectors/issues/22))

README.md

Lines changed: 97 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# PostCSS Custom Selectors
1+
# PostCSS Custom Selectors
22

3-
[![Build Status](https://travis-ci.org/postcss/postcss-custom-selectors.svg?branch=master)](https://travis-ci.org/postcss/postcss-custom-selectors)
4-
[![NPM Downloads](https://img.shields.io/npm/dm/postcss-custom-selectors.svg?style=flat)](https://www.npmjs.com/package/postcss-custom-selectors)
5-
[![NPM Version](http://img.shields.io/npm/v/postcss-custom-selectors.svg?style=flat)](https://www.npmjs.com/package/postcss-custom-selectors)
6-
[![License](https://img.shields.io/npm/l/postcss-custom-selectors.svg?style=flat)](http://opensource.org/licenses/MIT)
3+
[![Build Status](https://travis-ci.org/postcss/postcss-custom-selectors.svg?branch=master)](https://travis-ci.org/postcss/postcss-custom-selectors)
4+
[![NPM Downloads](https://img.shields.io/npm/dm/postcss-custom-selectors.svg?style=flat)](https://www.npmjs.com/package/postcss-custom-selectors)
5+
[![NPM Version](http://img.shields.io/npm/v/postcss-custom-selectors.svg?style=flat)](https://www.npmjs.com/package/postcss-custom-selectors)
6+
[![License](https://img.shields.io/npm/l/postcss-custom-selectors.svg?style=flat)](http://opensource.org/licenses/MIT)
77

88
> [PostCSS](https://github.com/postcss/postcss) plugin to transform [W3C CSS Extensions(Custom Selectors)](http://dev.w3.org/csswg/css-extensions/#custom-selectors) to more compatible CSS.
99
@@ -13,12 +13,12 @@
1313

1414
## Installation
1515

16-
$ npm install postcss-custom-selectors
16+
```console
17+
$ npm install postcss-custom-selectors
18+
```
1719

1820
## Quick Start
1921

20-
Example 1:
21-
2222
```js
2323
// dependencies
2424
var fs = require('fs')
@@ -33,7 +33,7 @@ var output = postcss()
3333
.use(selector())
3434
.process(css)
3535
.css
36-
36+
3737
console.log('\n====>Output CSS:\n', output)
3838
```
3939

@@ -50,7 +50,7 @@ input.css:
5050
```css
5151
@custom-selector :--heading h1, h2, h3, h4, h5, h6;
5252

53-
article :--heading + p {
53+
article :--heading + p {
5454
margin-top: 0;
5555
}
5656
```
@@ -63,25 +63,22 @@ article h2 + p,
6363
article h3 + p,
6464
article h4 + p,
6565
article h5 + p,
66-
article h6 + p {
66+
article h6 + p {
6767
margin-top: 0;
6868
}
6969
```
7070

7171
## CSS syntax
7272

73-
@custom-selector = @custom-selector :<extension-name> <selector>;
74-
73+
```css
74+
@custom-selector = @custom-selector :<extension-name> <selector>;
75+
```
7576

7677
## How to use
7778

78-
The custom selector is a pseudo-class, so we must use the `:--` to defined it.
79-
80-
For example to simulate [:any-link](http://dev.w3.org/csswg/selectors/#the-any-link-pseudo) selector:
81-
82-
Example 2:
79+
The custom selector is a pseudo-class, so you must use `:--` to define it.
8380

84-
input.css:
81+
For example to simulate [:any-link](http://dev.w3.org/csswg/selectors/#the-any-link-pseudo) selector:
8582

8683
```css
8784
@custom-selector :--any-link :link, :visited;
@@ -100,35 +97,100 @@ a:visited {
10097
}
10198
```
10299

103-
### Multiple selectors
100+
## Options
104101

105-
`@custom-selector` it **doesn’t support** call multiple custom selector in the same selector, e.g.
102+
### `lineBreak`
106103

107-
Example 3:
104+
_(default: `true`)_
105+
106+
Set whether multiple selector wrap.The default is turning on to be a newline.
107+
108+
Close the line breaks.
109+
110+
```js
111+
var options = {
112+
lineBreak: false
113+
}
114+
115+
var output = postcss(selector(options))
116+
.process(css)
117+
.css
118+
```
119+
120+
With the first example, the output will be:
108121

109122
```css
110-
@custom-selector :--heading h1, h2, h3, h4, h5, h6;
111-
@custom-selector :--any-link :link, :visited;
123+
article h1 + p, article h2 + p, article h3 + p, article h4 + p, article h5 + p, article h6 + p {
124+
margin-top: 0;
125+
}
126+
```
127+
128+
### `extensions`
129+
130+
_(default: `{}`)_
131+
132+
This option allows you to customize an object to set the `<extension-name>` (selector alias) and `<selector>`, these definitions will cover the same alias of `@custom-selector` in CSS.
133+
134+
```js
135+
var options = {
136+
extensions: {
137+
':--any' : 'section, article, aside, nav'
138+
}
139+
}
140+
141+
var output = postcss(selector(options))
142+
.process(css)
143+
.css;
144+
```
145+
146+
input.css
147+
148+
```css
149+
@custom-selector :--any .foo, .bar; /* No effect */
150+
:--any h1 {
151+
margin-top: 16px;
152+
}
153+
```
154+
155+
output:
156+
157+
```css
158+
/* No effect */
159+
section h1,
160+
article h1,
161+
aside h1,
162+
nav h1 {
163+
margin-top: 16px;
164+
}
165+
```
166+
167+
### `transformMatches`
168+
169+
_(default: `true`)_
112170

113-
.demo :--heading, a:--any-link {
114-
font-size: 32px;
171+
Allows you to limit transformation to `:matches()` usage
172+
If set to false:
173+
174+
input
175+
176+
```css
177+
@custom-selector :--foo .bar, .baz;
178+
.foo:--foo {
179+
margin-top: 16px;
115180
}
116181
```
117182

118-
This will throw an error CSS code.
183+
output
119184

120185
```css
121-
.demo h1,
122-
.demo h2,
123-
.demo h3,
124-
.demo h4,
125-
.demo h5,
126-
.demo h6,:link,
127-
:visited {
128-
font-size: 32px;
186+
.foo:matches(.bar, .baz) {
187+
margin-top: 16px;
129188
}
130189
```
131190

191+
192+
## Usage
193+
132194
### Node Watch
133195

134196
Dependence [chokidar](https://github.com/paulmillr/chokidar) module.
@@ -205,72 +267,6 @@ gulp.task('default', function () {
205267
gulp.watch('src/*.css', ['default']);
206268
```
207269

208-
209-
210-
### Options
211-
212-
#### 1. **`lineBreak`**(default: `true`)
213-
214-
Set whether multiple selector wrap.The default is turning on to be a newline.
215-
216-
Close the line breaks.
217-
218-
```js
219-
var options = {
220-
lineBreak: false
221-
}
222-
223-
var output = postcss(selector(options))
224-
.process(css)
225-
.css
226-
```
227-
228-
In the 'Example 1' `input.css` will output:
229-
230-
```css
231-
article h1 + p, article h2 + p, article h3 + p, article h4 + p, article h5 + p, article h6 + p {
232-
margin-top: 0;
233-
}
234-
```
235-
236-
#### 2. **`extensions`** (default: `{}`)
237-
238-
This option allows you to customize an object to set the `<extension-name>` (selector alias) and `<selector>`, these definitions will cover the same alias of `@custom-selector` in CSS.
239-
240-
```js
241-
var options = {
242-
extensions: {
243-
':--any' : 'section, article, aside, nav'
244-
}
245-
}
246-
247-
var output = postcss(selector(options))
248-
.process(css)
249-
.css;
250-
```
251-
252-
input.css
253-
254-
```css
255-
@custom-selector :--any .foo, .bar; /* No effect */
256-
:--any h1 {
257-
margin-top: 16px;
258-
}
259-
```
260-
261-
output:
262-
263-
```css
264-
/* No effect */
265-
section h1,
266-
article h1,
267-
aside h1,
268-
nav h1 {
269-
margin-top: 16px;
270-
}
271-
```
272-
273-
274270
## Contributing
275271

276272
* Install the relevant dependent module.

0 commit comments

Comments
 (0)