Skip to content

Commit

Permalink
Export variables with onVariables callback
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Dec 22, 2015
1 parent a8628dc commit e60b345
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ postcss([
]
```
### `onVariables`
Callback invoked once all variables in css are known. The callback receives an
object representing the known variables, including those explicitly-declared
by the [`variables`](#variables) option.
```js
postcss([
vars({
onVariables: function (variables) {
console.log('CSS Variables');
console.log(JSON.stringify(variables, null, 2));
}
})
]
```
### `unknown`
Callback on unknown variable name. It receives node instanc, variable name
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,9 @@ module.exports = postcss.plugin('postcss-simple-vars', function (opts) {
}

});

if ( opts.onVariables ) {
opts.onVariables(variables);
}
};
});
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ describe('postcss-simple-vars', function () {
expect(result).to.eql([['width', 'one']]);
});

it('has callback for exporting variables', function (done) {
test('$one: 1;', '', { onVariables: function (variables) {
expect(variables.one).to.eql('1');
done();
} });
});

it('overrides unknown variable', function () {
var unknown = function () {
return 'unknown';
Expand Down

0 comments on commit e60b345

Please sign in to comment.