postcss-variables
Advanced tools
Comparing version 0.1.0 to 0.1.1
18
index.js
@@ -9,3 +9,2 @@ const postcss = require('postcss'); | ||
const variablesInString = /(^|[^\\])\$(?:\(([A-z][\w-.]*)\)|([A-z][\w-.]*))/g; | ||
const wrappingParen = /^\((.*)\)$/g; | ||
@@ -22,8 +21,3 @@ /** | ||
let array = postcss.list | ||
.comma(String(string)) | ||
.map(substring => { | ||
return wrappingParen.test(substring) ? | ||
getArrayedString(substring.replace(wrappingParen, '$1')) : | ||
substring; | ||
}); | ||
.comma(String(string)); | ||
@@ -163,2 +157,10 @@ return first && array.length === 1 ? array[0] : array; | ||
function eachMixin(node, parent, nodeCount) { | ||
node.arguments = node.arguments.map(arg => { | ||
return getVariableTransformedString(parent, arg); | ||
}); | ||
return nodeCount; | ||
} | ||
/** | ||
@@ -180,2 +182,4 @@ * Traverse every node | ||
index = eachAtRule(node, parent, index); | ||
} else if (node.type === 'mixin') { | ||
index = eachMixin(node, parent, index); | ||
} | ||
@@ -182,0 +186,0 @@ |
{ | ||
"name": "postcss-variables", | ||
"version": "0.1.0", | ||
"description": "Converts variables into CSS", | ||
"version": "0.1.1", | ||
"description": "PostCSS plugin that converts variables into CSS", | ||
"main": "index.js", | ||
"keywords": [ | ||
"postcss", | ||
"css", | ||
"postcss-plugin", | ||
"variables", | ||
"vars" | ||
], | ||
"scripts": { | ||
@@ -10,3 +17,3 @@ "test": "mocha ./tests.js" | ||
"author": "Nathan Hood", | ||
"license": "CC0-1.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -17,4 +24,6 @@ "postcss": "^5.2.6" | ||
"chai": "^3.5.0", | ||
"mocha": "^3.2.0" | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"postcss-js-mixins": "^0.1" | ||
} | ||
} |
# PostCSS Variables | ||
[![Build Status](https://travis-ci.org/nathanhood/postcss-variables.svg?branch=master)](https://travis-ci.org/nathanhood/postcss-variables) | ||
[![codecov](https://codecov.io/gh/nathanhood/postcss-variables/branch/master/graph/badge.svg)](https://codecov.io/gh/nathanhood/postcss-variables) | ||
<img align="right" width="135" height="95" src="http://postcss.github.io/postcss/logo-leftp.png" title="Philosopher’s stone, logo of PostCSS"> | ||
@@ -4,0 +7,0 @@ |
66
tests.js
@@ -21,2 +21,13 @@ const expect = require('chai').expect; | ||
function processMixins(input, expected, opts = {}, errors = 0) { | ||
return postcss([ plugin(opts) ]).process(input, { | ||
parser: require('postcss-js-mixins/parser/parse'), | ||
stringifier: require('postcss-js-mixins/parser/stringify') | ||
}) | ||
.then((result) => { | ||
expect(result.css).to.equal(expected); | ||
expect(result.warnings().length).to.equal(errors); | ||
}); | ||
} | ||
describe('Declarations', () => { | ||
@@ -92,2 +103,15 @@ it('should resolve values', () => { | ||
}); | ||
it('should resolve variables with variables as values', () => { | ||
return process( | ||
`$baseDir: /img; | ||
$path: $(baseDir)/share.png; | ||
body { | ||
background-image: url('$(path)'); | ||
}`, | ||
`body { | ||
background-image: url('/img/share.png'); | ||
}` | ||
); | ||
}); | ||
}); | ||
@@ -273,2 +297,44 @@ | ||
// TODO: Finish @rule tests (font-face, supports, etc) | ||
}); | ||
describe('Mixins', () => { | ||
it('should resolve params passed into mixins (postcss-js-mixins)', () => { | ||
return processMixins( | ||
`$color: #000; | ||
.block { | ||
mixin($color); | ||
mixin($colors.primary); | ||
}`, | ||
`.block { | ||
mixin(#000); | ||
mixin(#fff); | ||
}`, | ||
{ | ||
globals: { | ||
colors: { | ||
primary: '#fff' | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
it('should resolve mixture of params passed into mixin', () => { | ||
return processMixins( | ||
`$color: #000; | ||
.block { | ||
mixin($color, url('string.png'), 10, 30px, $colors.primary); | ||
}`, | ||
`.block { | ||
mixin(#000, url('string.png'), 10, 30px, #fff); | ||
}`, | ||
{ | ||
globals: { | ||
colors: { | ||
primary: '#fff' | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
14376
7
0
100
479
108
4