postcss-vertical-rhythm
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,2 +1,6 @@ | ||
## v1.1.0 | ||
- Use [`node.error`](https://github.com/postcss/postcss/blob/master/docs/guidelines/plugin.md#31-use-nodeerror-on-css-relevant-errors) for errors. | ||
- Correct readme for installing. | ||
## v1.0.0 | ||
- Initial release. |
30
index.js
var postcss = require('postcss'); | ||
var spacingValue; | ||
@@ -37,13 +36,13 @@ /** | ||
* Gets the font declaration properties. | ||
* @param {String} declValue | ||
* @param {Object} decl | ||
* @return {Array} | ||
*/ | ||
var getProps = function (declValue) { | ||
var getProps = function (decl) { | ||
// Matches {$1:font-size}{$2:unit}/{$3:line-height}. | ||
var fontProps = declValue.match(/(\d+|\d+?\.\d+)(r?em|px|%)(?:\s*\/\s*)(\d+|\d+?\.\d+)\s+/); | ||
var fontProps = decl.value.match(/(\d+|\d+?\.\d+)(r?em|px|%)(?:\s*\/\s*)(\d+|\d+?\.\d+)\s+/); | ||
// Make sure the line-height value is declared. | ||
if (!fontProps) { | ||
throw new Error('Font declaration is invalid. Make sure line-height is set.'); | ||
throw decl.error('Font declaration is invalid. Make sure line-height is set.'); | ||
} | ||
@@ -55,10 +54,10 @@ | ||
/** | ||
* Gets the spacing value. | ||
* @param {String} declValue | ||
* Gets the rhythm value. | ||
* @param {Object} decl | ||
* @return {Number} | ||
*/ | ||
var getSpacingValue = function (declValue) { | ||
var val = parseFloat(declValue) || 1; | ||
var getRhythmValue = function (decl, rhythmValue) { | ||
var val = parseFloat(decl.value) || 1; | ||
return spacingValue * val; | ||
return rhythmValue * val; | ||
}; | ||
@@ -70,2 +69,3 @@ | ||
var rhythmUnit = 'vr'; | ||
var rhythmValue; | ||
@@ -78,13 +78,13 @@ return function (css) { | ||
if (decl.prop === 'font') { | ||
var props = getProps(decl.value); | ||
var props = getProps(decl); | ||
spacingValue = calcLineHeight(props); | ||
rhythmValue = calcLineHeight(props); | ||
} else { | ||
throw new Error('font declaration not found in ' + rootSelector); | ||
throw decl.error('Font declaration not found in ' + rootSelector); | ||
} | ||
} | ||
// Calculate spacing value. | ||
// Calculate ryhthm value. | ||
if (decl.value.indexOf(rhythmUnit) !== -1) { | ||
decl.value = getSpacingValue(decl.value) + 'px'; | ||
decl.value = getRhythmValue(decl, rhythmValue) + 'px'; | ||
} | ||
@@ -91,0 +91,0 @@ }); |
{ | ||
"name": "postcss-vertical-rhythm", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A PostCSS plugin to create a custom vertical rhythm unit from the base font-size and line-height.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
# postcss-vertical-ryhthm [![Build Status][ci-img]][ci] | ||
# postcss-vertical-rhythm [![Build Status][ci-img]][ci] | ||
[PostCSS]: https://github.com/postcss/postcss | ||
@@ -49,3 +49,3 @@ [ci-img]: https://travis-ci.org/markgoodyear/postcss-vertical-rhythm.svg?branch=master | ||
``` | ||
npm install postcss-vertical-ryhthm --save-dev | ||
npm install postcss-vertical-rhythm --save-dev | ||
``` | ||
@@ -55,3 +55,3 @@ | ||
```js | ||
postcss([ require('vertical-ryhthm')({ options }) ]) | ||
postcss([ require('postcss-vertical-rhythm')(options) ]) | ||
``` | ||
@@ -61,4 +61,3 @@ | ||
## Licence | ||
Released under the MIT license. |
6276
61