Skip to content

Commit 888ab46

Browse files
committed
Merge pull request #2 from zoubin/master
Support specifying transform names
2 parents 39bed04 + 22b156b commit 888ab46

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

.coveralls.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var fixtures = path.resolve.bind(path, __dirname, 'fixtures')
2020

2121
postcss(url([
2222
[ util.inline, { maxSize: 5 } ],
23-
[ util.copy, { assetOutFolder: fixtures('build', 'images') } ],
23+
// equivalent with util.copy
24+
[ 'copy', { assetOutFolder: fixtures('build', 'images') } ],
2425
]))
2526
.process(
2627
'.a{ background-image: url(images/octocat_setup.png); }',
@@ -41,7 +42,11 @@ Type: `Array`
4142

4243
Default: `[ util.rebase ]`
4344

44-
An array of transforms
45+
An array of transforms.
46+
47+
If an element is not a function,
48+
it should be the name of a method exported by `util`:
49+
`'copy'`, `'inline'`, `'rebase'`.
4550

4651
### transforms
4752

@@ -52,7 +57,8 @@ Signature: `transformFn(result, ...args)`
5257
Function to transform url,
5358
through modifying `result.url`
5459

55-
If `Array`, `args` will be the elements from the second.
60+
If `Array`, the first element should be the transform function,
61+
and elements after the first will be treated as its arguments `args`.
5662

5763
#### result
5864

lib/result.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const Url = require('url')
44
const path = require('path')
55
const Asset = require('./asset')
6+
const util = require('./util')
67

78
class Result {
89
constructor(url, opts) {
@@ -46,6 +47,9 @@ class Result {
4647
})
4748
return trs.reduce(function (p, tr) {
4849
return p.then(function () {
50+
if (typeof tr[0] === 'string') {
51+
tr[0] = util[tr[0]]
52+
}
4953
let r = tr[0].apply(null, tr.slice(1))
5054
if (r && typeof r.then === 'function') {
5155
return r

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "npm run lint && tap test/*.js",
8+
"cov": "npm run lint && tap --cov test/*.js",
89
"lint": "eslint *.js 'lib/**/*.js' test/*.js bin/*.js",
9-
"coveralls": "COVERALLS_REPO_TOKEN=REPO_TOKEN tap test/*.js"
10+
"coveralls": "COVERALLS_REPO_TOKEN=m8BySBat6AaALacZWXaSBWhuVYOo6Yd7y tap test/*.js"
1011
},
1112
"repository": {
1213
"type": "git",

test/custom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('custom', function(t) {
1818

1919
result.url = path.join(base, path.basename(result.url))
2020
}, 'i'],
21-
util.copy,
21+
'copy',
2222
])
2323
let body = '.a{ background-image: url(images/octocat_setup.png) url(images/octocat_fork.png); }'
2424
let expectedBody = [ '.a{background-image:url(', ')url(i/octocat_fork.png);}' ]

0 commit comments

Comments
 (0)