Skip to content

Commit f986031

Browse files
jonathantnealromainmenke
authored andcommitted
4.0.0
- Added: Support for PostCSS v6 - Added: Support for Node v4 - Removed: `prefix` option, as that would be non-spec
1 parent 2114394 commit f986031

File tree

11 files changed

+92
-183
lines changed

11 files changed

+92
-183
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node_modules
2-
npm-debug.log
3-
test/*.result.css
2+
.*
3+
!.gitignore
4+
!.tape.js
5+
!.travis.yml
6+
*.log*
7+
*.result.css

plugins/postcss-pseudo-class-any-link/.tape.js

-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ module.exports = {
22
'postcss-pseudo-class-any-link': {
33
'basic': {
44
message: 'supports basic usage'
5-
},
6-
'basic:w-prefix': {
7-
message: 'ignores basic usage when { prefix: "x" }',
8-
options: {
9-
prefix: 'x'
10-
}
11-
},
12-
'prefix': {
13-
message: 'supports prefix usage'
14-
},
15-
'prefix:w-prefix': {
16-
message: 'supports prefix usage when { prefix: "x" }',
17-
options: {
18-
prefix: 'x'
19-
}
205
}
216
}
227
};
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: node_js
22
node_js:
3-
- stable
3+
- 4

plugins/postcss-pseudo-class-any-link/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to :any-link
22

3+
### 4.0.0 (May 10, 2017)
4+
5+
- Added: Support for PostCSS v6
6+
- Added: Support for Node v4
7+
- Removed: `prefix` option, as that would be non-spec
8+
39
### 3.0.1 (December 8, 2016)
410

511
- Updated: Use destructing assignment on plugin options

plugins/postcss-pseudo-class-any-link/README.md

+20-31
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
# :any-link <a href="https://github.com/postcss/postcss"><img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right"></a>
1+
# :any-link [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
22

33
[![NPM Version][npm-img]][npm-url]
44
[![Build Status][cli-img]][cli-url]
5-
[![Licensing][lic-image]][lic-url]
6-
[![Changelog][log-image]][log-url]
7-
[![Gitter Chat][git-image]][git-url]
5+
[![Licensing][lic-img]][lic-url]
6+
[![Changelog][log-img]][log-url]
7+
[![Gitter Chat][git-img]][git-url]
88

99
[:any-link] lets you to use the proposed [`:any-link`] pseudo-class in CSS.
1010

1111
`:any-link` simplifies selectors targeting links, as the naming of `:link` is misleading; it specifically means unvisited links only, rather than all links.
1212

1313
```css
14-
/* before */
15-
1614
nav :any-link > span {
1715
background-color: yellow;
1816
}
1917

20-
/* after */
18+
/* becomes */
2119

22-
nav :link > span,
23-
nav :visited > span {
20+
nav :link > span, nav :visited > span {
2421
background-color: yellow;
2522
}
2623
```
@@ -29,28 +26,20 @@ From the [proposal]:
2926

3027
> The [`:any-link`] pseudo-class represents an element that acts as the source anchor of a hyperlink. It matches an element if the element would match [`:link`] or [`:visited`].
3128
32-
## Options
33-
34-
**prefix** (string): prepends a prefix (surrounded by dashes) to the pseudo-class, preventing any clash with native syntax.
35-
36-
```js
37-
{
38-
prefix: 'foo' // pseudo-class becomes :-foo-any-link
39-
}
40-
```
41-
4229
## Usage
4330

4431
Add [:any-link] to your build tool:
4532

4633
```bash
47-
npm install :any-link --save-dev
34+
npm install postcss-pseudo-class-any-link --save-dev
4835
```
4936

5037
#### Node
5138

39+
Use [:any-link] to process your CSS:
40+
5241
```js
53-
require(':any-link').process(YOUR_CSS, { /* options */ });
42+
require('postcss-pseudo-class-any-link').process(YOUR_CSS);
5443
```
5544

5645
#### PostCSS
@@ -61,12 +50,12 @@ Add [PostCSS] to your build tool:
6150
npm install postcss --save-dev
6251
```
6352

64-
Load [:any-link] as a PostCSS plugin:
53+
Use [:any-link] as a plugin:
6554

6655
```js
6756
postcss([
68-
require(':any-link')({ /* options */ })
69-
]).process(YOUR_CSS, /* options */);
57+
require('postcss-pseudo-class-any-link')()
58+
]).process(YOUR_CSS);
7059
```
7160

7261
#### Gulp
@@ -77,15 +66,15 @@ Add [Gulp PostCSS] to your build tool:
7766
npm install gulp-postcss --save-dev
7867
```
7968

80-
Enable [:any-link] within your Gulpfile:
69+
Use [:any-link] in your Gulpfile:
8170

8271
```js
8372
var postcss = require('gulp-postcss');
8473

8574
gulp.task('css', function () {
8675
return gulp.src('./src/*.css').pipe(
8776
postcss([
88-
require(':any-link')({ /* options */ })
77+
require('postcss-pseudo-class-any-link')()
8978
])
9079
).pipe(
9180
gulp.dest('.')
@@ -101,7 +90,7 @@ Add [Grunt PostCSS] to your build tool:
10190
npm install grunt-postcss --save-dev
10291
```
10392

104-
Enable [:any-link] within your Gruntfile:
93+
Use [:any-link] in your Gruntfile:
10594

10695
```js
10796
grunt.loadNpmTasks('grunt-postcss');
@@ -110,7 +99,7 @@ grunt.initConfig({
11099
postcss: {
111100
options: {
112101
use: [
113-
require(':any-link')({ /* options */ })
102+
require('postcss-pseudo-class-any-link')()
114103
]
115104
},
116105
dist: {
@@ -145,11 +134,11 @@ Here are a few other ways to simulate the effect of [PostCSS Pseudo-Class Any-Li
145134
[cli-url]: https://travis-ci.org/jonathantneal/postcss-pseudo-class-any-link
146135
[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-pseudo-class-any-link.svg
147136
[lic-url]: LICENSE.md
148-
[lic-image]: https://img.shields.io/npm/l/postcss-pseudo-class-any-link.svg
137+
[lic-img]: https://img.shields.io/npm/l/postcss-pseudo-class-any-link.svg
149138
[log-url]: CHANGELOG.md
150-
[log-image]: https://img.shields.io/badge/changelog-md-blue.svg
139+
[log-img]: https://img.shields.io/badge/changelog-md-blue.svg
151140
[git-url]: https://gitter.im/postcss/postcss
152-
[git-image]: https://img.shields.io/badge/chat-gitter-blue.svg
141+
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
153142

154143
[:any-link]: https://github.com/jonathantneal/postcss-pseudo-class-any-link
155144
[`:any-link`]: http://dev.w3.org/csswg/selectors/#any-link-pseudo
+47-65
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,55 @@
1+
'use strict';
2+
13
// tooling
24
const postcss = require('postcss');
35
const parser = require('postcss-selector-parser');
46

57
// plugin
6-
module.exports = postcss.plugin('postcss-pseudo-class-any-link', ({
7-
prefix = ''
8-
} = {}) => {
9-
// dashed prefix
10-
const dashedPrefix = prefix ? `-${ prefix }-` : '';
11-
12-
// any-link value
13-
const anyLinkValue = `:${ dashedPrefix }any-link`;
14-
15-
// selector matcher
16-
const selectorMatch = new RegExp(`${ dashedPrefix }any-link`);
17-
18-
return (css) => {
19-
// walk each matching rule
20-
css.walkRules(selectorMatch, (rule) => {
21-
const rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector;
22-
23-
// workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556
24-
if (rawSelector[rawSelector.length - 1] !== ':') {
25-
// update the selector
26-
rule.selector = parser((selectors) => {
27-
// cache variables
28-
let node;
29-
let nodeIndex;
30-
let selector;
31-
let selectorLink;
32-
let selectorVisited;
33-
34-
// cache the selector index
35-
let selectorIndex = -1;
36-
37-
// for each selector
38-
while (selector = selectors.nodes[++selectorIndex]) {
39-
// reset the node index
40-
nodeIndex = -1;
41-
42-
// for each node
43-
while (node = selector.nodes[++nodeIndex]) {
44-
// if the node value matches the any-link value
45-
if (node.value === anyLinkValue) {
46-
// clone the selector
47-
selectorLink = selector.clone();
48-
selectorVisited = selector.clone();
49-
50-
// update the matching clone values
51-
selectorLink.nodes[nodeIndex].value = ':link';
52-
selectorVisited.nodes[nodeIndex].value = ':visited';
53-
54-
// replace the selector with the clones and roll back the selector index
55-
selectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited);
56-
57-
// stop updating the selector
58-
break;
59-
}
8+
module.exports = postcss.plugin('postcss-pseudo-class-any-link', () => (css) => {
9+
// walk each matching rule
10+
css.walkRules(/:any-link/, (rule) => {
11+
const rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector;
12+
13+
// workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556
14+
if (rawSelector[rawSelector.length - 1] !== ':') {
15+
// update the selector
16+
rule.selector = parser((selectors) => {
17+
// cache variables
18+
let node;
19+
let nodeIndex;
20+
let selector;
21+
let selectorLink;
22+
let selectorVisited;
23+
24+
// cache the selector index
25+
let selectorIndex = -1;
26+
27+
// for each selector
28+
while (selector = selectors.nodes[++selectorIndex]) {
29+
// reset the node index
30+
nodeIndex = -1;
31+
32+
// for each node
33+
while (node = selector.nodes[++nodeIndex]) {
34+
// if the node value matches the any-link value
35+
if (node.value === ':any-link') {
36+
// clone the selector
37+
selectorLink = selector.clone();
38+
selectorVisited = selector.clone();
39+
40+
// update the matching clone values
41+
selectorLink.nodes[nodeIndex].value = ':link';
42+
selectorVisited.nodes[nodeIndex].value = ':visited';
43+
44+
// replace the selector with the clones and roll back the selector index
45+
selectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited);
46+
47+
// stop updating the selector
48+
break;
6049
}
6150
}
62-
}).process(rawSelector).result;
63-
}
64-
});
65-
};
51+
}
52+
}).process(rawSelector).result;
53+
}
54+
});
6655
});
67-
68-
// override plugin#process
69-
module.exports.process = function (cssString, pluginOptions, processOptions) {
70-
return postcss([
71-
1 in arguments ? module.exports(pluginOptions) : module.exports()
72-
]).process(cssString, processOptions);
73-
};

plugins/postcss-pseudo-class-any-link/package.json

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-pseudo-class-any-link",
3-
"version": "3.0.1",
3+
"version": "4.0.0",
44
"description": "Use the proposed :any-link pseudo-class in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"license": "CC0-1.0",
@@ -12,39 +12,31 @@
1212
"index.js"
1313
],
1414
"scripts": {
15-
"lint": "echint && eslint index.js && jscs index.js",
15+
"clean": "git clean -X -d -f",
1616
"prepublish": "npm test",
17-
"tape": "postcss-tape",
18-
"test": "npm run lint && postcss-tape"
17+
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape",
18+
"test:js": "eslint *.js --cache --ignore-pattern .gitignore",
19+
"test:tape": "postcss-tape"
1920
},
2021
"engines": {
21-
"node": ">=6.9.1"
22+
"node": ">=4.0.0"
2223
},
2324
"dependencies": {
24-
"postcss": "^5.2.6",
25-
"postcss-selector-parser": "^2.2.2"
25+
"postcss": "^6.0.1",
26+
"postcss-selector-parser": "^2.2.3"
2627
},
2728
"devDependencies": {
28-
"echint": "^2.1.0",
29-
"echint-config-dev": "1.0.0",
30-
"eslint": "^3.12.1",
31-
"eslint-config-dev": "1.0.0",
32-
"jscs": "^3.0.7",
33-
"jscs-config-dev": "1.0.1",
34-
"postcss-tape": "1.3.0"
35-
},
36-
"echint": {
37-
"extends": "dev"
29+
"eslint": "^3.19.0",
30+
"eslint-config-dev": "2.0.0",
31+
"postcss-tape": "2.0.1",
32+
"pre-commit": "^1.2.2"
3833
},
3934
"eslintConfig": {
4035
"extends": "dev",
4136
"parserOptions": {
4237
"sourceType": "module"
4338
}
4439
},
45-
"jscsConfig": {
46-
"preset": "dev"
47-
},
4840
"keywords": [
4941
"postcss",
5042
"css",

plugins/postcss-pseudo-class-any-link/test/basic.w-prefix.expect.css

-12
This file was deleted.

plugins/postcss-pseudo-class-any-link/test/prefix.css

-12
This file was deleted.

0 commit comments

Comments
 (0)