Permalink
Browse files

add var(object) support

  • Loading branch information...
1 parent a921bd9 commit 5a00a23fbc42cefd559a941aedf8b049fd52fb9f @tj tj committed Apr 4, 2013
Showing with 8 additions and 9 deletions.
  1. +3 −3 Readme.md
  2. +3 −2 lib/plugins/vars.js
  3. +0 −1 test/fixtures/vars.css
  4. +1 −2 test/fixtures/vars.out.css
  5. +1 −1 test/rework.js
View
@@ -80,7 +80,7 @@ $ rework -v webkit,moz < my.css > my.reworked.css
- [prefixSelectors](#prefixselectorsstring) — add prefixes to selectors
- [opacity](#opacity) — add IE opacity support
- [url](#urlcallback) — rewrite `url()`s with a callback function
- - [vars](#vars) — add css variable support
+ - [vars](#varsobject) — add css variable support
- [keyframes](#keyframesvendors) — add __@keyframe__ vendor prefixing
- [colors](#colors) — add colour helpers like `rgba(#fc0, .5)`
- [references](#references) — add property references support `height: @width` etc
@@ -547,11 +547,11 @@ button.round {
}
```
-### .vars()
+### .vars([object])
Add variable support. Note that this does not cascade like the CSS variable
spec does, thus this is _not_ some sort of fallback mechanism, just a useful
- feature.
+ feature. Optionally you may pass an `object` of variables from js-land.
```css
:root {
View
@@ -24,12 +24,13 @@ var visit = require('../visit');
*
*/
-module.exports = function() {
- var map = {};
+module.exports = function(map) {
+ map = map || {};
function replace(str) {
return str.replace(/\bvar\((.*?)\)/g, function(_, name){
var val = map[name];
+ if (!val) throw new Error('variable "' + name + '" is undefined');
if (val.match(/\bvar\(/)) val = replace(val);
return val;
});
View
@@ -1,6 +1,5 @@
:root {
var-header-color: #06c;
- var-main-color: #c06;
}
div {
@@ -1,6 +1,5 @@
:root {
- var-header-color: #06c;
- var-main-color: #c06
+ var-header-color: #06c
}
div {
View
@@ -223,7 +223,7 @@ describe('rework', function(){
it('should add variable support', function(){
rework(fixture('vars'))
.vendors(vendors)
- .use(rework.vars())
+ .use(rework.vars({ 'main-color': '#c06' }))
.toString()
.should.equal(fixture('vars.out'));
})

0 comments on commit 5a00a23

Please sign in to comment.