postcss-prettify
Advanced tools
Comparing version
@@ -5,2 +5,9 @@ # Change Log | ||
## 0.2.0 — 3/11/16 | ||
Restructured logic for easy extending. | ||
**ADD** | ||
- prepend newline to @rules (previously only affected non-@rules) | ||
## 0.1.1 — 3/10/16 | ||
@@ -7,0 +14,0 @@ |
37
index.js
@@ -0,13 +1,30 @@ | ||
// import modules | ||
//------------------------------------------------------------------------------ | ||
const postcss = require('postcss') | ||
module.exports = postcss.plugin('postcss-beautify', () => css => | ||
css.walkRules(rule => { | ||
// one selector per line | ||
if (rule.selector.indexOf(', ') >= 0) { | ||
rule.selector = rule.selector.replace(/, /g, ',\n') | ||
} | ||
// define modifiers | ||
//------------------------------------------------------------------------------ | ||
const call = mods => entity => mods.forEach(mod => mod.call(entity)) | ||
// empty line between rules | ||
if (rule.raws.before !== '') rule.raws.before = '\n\n' | ||
}) | ||
) | ||
function precedingEmptyLine() { | ||
if (this.raws.before === '\n') this.raws.before = '\n\n' | ||
} | ||
function oneSelectorPerLine() { | ||
if (this.selector.indexOf(', ') >= 0) { | ||
this.selector = this.selector.replace(/, /g, ',\n') | ||
} | ||
} | ||
// call modifiers and export | ||
//------------------------------------------------------------------------------ | ||
module.exports = postcss.plugin('postcss-prettify', () => css => { | ||
css.walkRules(call([ | ||
oneSelectorPerLine, | ||
precedingEmptyLine, | ||
])) | ||
css.walkAtRules(call([ | ||
precedingEmptyLine, | ||
])) | ||
}) |
{ | ||
"name": "postcss-prettify", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "prettify postcss output", | ||
@@ -30,3 +30,2 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"co-mocha": "^1.1.2", | ||
@@ -42,8 +41,2 @@ "eslint": "^2.3.0", | ||
"rules": { | ||
"no-param-reassign": [ | ||
2, | ||
{ | ||
"props": false | ||
} | ||
], | ||
"semi": [ | ||
@@ -50,0 +43,0 @@ 2, |
@@ -23,4 +23,6 @@ # `postcss-prettify` [![build][1]][2] [![coverage][3]][4] | ||
} | ||
.baz { | ||
background: blue; | ||
@media only screen and (min-width: 600px) { | ||
.baz { | ||
background: blue; | ||
} | ||
} | ||
@@ -36,4 +38,6 @@ ``` | ||
.baz { | ||
background: blue; | ||
@media only screen and (min-width: 600px) { | ||
.baz { | ||
background: blue; | ||
} | ||
} | ||
@@ -40,0 +44,0 @@ ``` |
// utils --------------------------------------------------- | ||
const path = require('path') | ||
const assert = require('assert') | ||
const fs = require('mz/fs') | ||
const postcss = require('postcss') | ||
const assert = require('chai').assert | ||
const prettify = require('..') | ||
@@ -8,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6181
15.21%6
-14.29%79
61.22%70
6.06%