Skip to content

Commit dd2bd33

Browse files
committed
API change (plugin now return a function)
See changelog for more informations poke @jonathanong
1 parent 701023f commit dd2bd33

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.0 - 2014-08-06
2+
3+
* Plugin now return a function to have a consistent api. ([ref1](https://github.com/ianstormtaylor/rework-color-function/issues/6), [ref2](https://twitter.com/jongleberry/status/496552790416576513))
4+
15
# 1.0.0 - 2014-08-04
26

37
First release based on [rework-calc](https://github.com/reworkcss/rework-calc) v1.1.0 (code mainly exported to [`reduce-css-calc`](https://github.com/MoOx/reduce-css-calc))

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ npm install postcss-calc
1717
var postcss = require("postcss")
1818
var calc = require("postcss-calc")
1919

20-
var css = postcss(calc).process(cssString).css;
20+
var css = postcss()
21+
.use(calc())
22+
.process(cssString)
23+
.css
2124
```
2225

2326
## Supported feature
@@ -41,7 +44,7 @@ var css = fs.readFileSync("style.css", "utf8")
4144

4245
var output = postcss()
4346
.use(customProperties())
44-
.use(calc)
47+
.use(calc())
4548
.process(css)
4649
.css
4750
```

index.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Module dependencies.
33
*/
4-
var reduceCssCalc = require("reduce-css-calc")
4+
var reduceCSSCalc = require("reduce-css-calc")
55

66
/**
77
* Expose `plugin`.
@@ -10,47 +10,31 @@ var reduceCssCalc = require("reduce-css-calc")
1010
module.exports = plugin
1111

1212
/**
13-
* Plugin to convert CSS color functions.
13+
* Plugin to convert all function calls.
1414
*
1515
* @param {Object} stylesheet
1616
*/
1717

18-
function plugin(style) {
19-
style.eachRule(rule)
20-
}
21-
22-
/**
23-
* Convert an entire `rule`.
24-
*
25-
* @param {Object} rule
26-
*/
27-
28-
function rule(obj) {
29-
obj.each(declaration)
30-
}
31-
32-
/**
33-
* Convert a declaration.
34-
*
35-
* @param {Object} dec
36-
*/
37-
38-
function declaration(dec) {
39-
if (!dec.value) {
40-
return
41-
}
42-
43-
try {
44-
dec.value = convert(dec.value)
45-
}
46-
catch (err) {
47-
err.position = dec.position
48-
throw err
18+
function plugin() {
19+
return function(style) {
20+
style.eachDecl(function declaration(dec) {
21+
if (!dec.value) {
22+
return
23+
}
24+
25+
try {
26+
dec.value = convert(dec.value)
27+
}
28+
catch (err) {
29+
err.position = dec.position
30+
throw err
31+
}
32+
})
4933
}
5034
}
5135

5236
/**
53-
* Reduce css calc()
37+
* Reduce CSS calc()
5438
*
5539
* @param {String} string
5640
* @return {String}
@@ -61,5 +45,5 @@ function convert(string) {
6145
return string
6246
}
6347

64-
return reduceCssCalc(string)
48+
return reduceCSSCalc(string)
6549
}

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function fixture(name) {
1313
test("resolve what is possible in complex calc", function(t) {
1414
var actual = postcss()
1515
.use(customProperties())
16-
.use(calc)
16+
.use(calc())
1717
.process(fixture("calc"))
1818
.css
1919
.trim()

0 commit comments

Comments
 (0)