Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from jonathantneal/feature/postcss6-and-updates
Browse files Browse the repository at this point in the history
Use PostCSS 6 and improve accuracy of the plugin
  • Loading branch information
MoOx authored May 11, 2017
2 parents f22f965 + 99053e6 commit 6ec0238
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,5 @@
"requireCapitalizedConstructors": true,
"safeContextKeyword": "that",
"requireDotNotation": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"requireSpaceAfterLineComment": true
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
language: node_js
node_js:
- 4
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.0.0 - 2016-05-10

- Added: compatibility with postcss v6.x

# 2.0.1 - 2016-11-28

- Bump `color` dependency version
Expand Down
25 changes: 14 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
/**
* Module dependencies.
*/
var postcss = require("postcss")
var color = require("color")("rebeccapurple").rgbString()
const postcss = require("postcss")
const valueParser = require("postcss-value-parser")
const color = "#639"

/**
* PostCSS plugin to convert colors
*/
module.exports = postcss.plugin("postcss-color-rebeccapurple", function() {
return function(style) {
style.walkDecls(function(decl) {
var value = decl.value;
module.exports = postcss.plugin("postcss-color-rebeccapurple", () => (style) => {
style.walkDecls((decl) => {
const value = decl.value;

if (value && value.indexOf("rebeccapurple") !== -1) {
decl.value = value.replace(/(rebeccapurple)\b/gi, color)
}
})
}
if (value && value.indexOf("rebeccapurple") !== -1) {
decl.value = valueParser(value).walk((node) => {
if (node.type === "word" && node.value === "rebeccapurple") {
node.value = color
}
}).toString()
}
})
})
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-color-rebeccapurple",
"version": "2.0.1",
"version": "3.0.0",
"description": "PostCSS plugin to transform W3C CSS rebeccapurple color to more compatible CSS (rgb())",
"keywords": [
"css",
Expand All @@ -21,14 +21,14 @@
"index.js"
],
"dependencies": {
"color": "^0.11.4",
"postcss": "^5.0.4"
"postcss": "^6.0.1",
"postcss-value-parser": "^3.3.0"
},
"devDependencies": {
"jscs": "^1.6.2",
"jshint": "^2.5.6",
"jscs": "^3.0.7",
"jshint": "^2.9.4",
"npmpub": "^3.1.0",
"tape": "^4.0.0"
"tape": "^4.6.3"
},
"scripts": {
"lint": "npm run jscs && npm run jshint",
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/rebeccapurple.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ body {
color: rebeccapurple;
background: linear-gradient(rebeccapurple, blue 50%, rebeccapurple);
}

a {
color: oldrebeccapurple;
}
8 changes: 6 additions & 2 deletions test/fixtures/rebeccapurple.expected.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
body {
color: rgb(102, 51, 153);
background: linear-gradient(rgb(102, 51, 153), blue 50%, rgb(102, 51, 153));
color: #639;
background: linear-gradient(#639, blue 50%, #639);
}

a {
color: oldrebeccapurple;
}

0 comments on commit 6ec0238

Please sign in to comment.