postcss-style-docs
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "postcss-style-docs", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "PostCSS plugin for dynamically adding documentation to styles", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,3 +7,10 @@ # postcss-style-docs | ||
The `postcss-style-docs` pluin will walk through your input CSS and create a map of styles to documentation blocks as a message output. | ||
```css | ||
/** | ||
* @docs | ||
* This is a documentation block for the .foo class | ||
* it can be multiple lines | ||
*/ | ||
.foo { | ||
@@ -28,20 +35,35 @@ /* Input example */ | ||
**Step 2:** Check you project for existed PostCSS config: `postcss.config.js` | ||
in the project root, `"postcss"` section in `package.json` | ||
or `postcss` in bundle config. | ||
**Step 2:** The `postcss-style-docs` plugin works best when manually calling `postcss.process` which enables users to get data out of the plugin: | ||
If you do not use PostCSS, add it according to [official docs] | ||
and set this plugin in settings. | ||
```javascript | ||
import postcss from 'postcss'; | ||
import { getDocsMessage, styleDocsPlugin } from './lib/cjs/index'; | ||
**Step 3:** Add the plugin to plugins list: | ||
const inputCSS = ` | ||
/** | ||
* @docs | ||
* We're doing something really fancy and our users are going | ||
* to love it. | ||
*/ | ||
.something-fancy { | ||
color: tomato; | ||
} | ||
```diff | ||
module.exports = { | ||
plugins: [ | ||
+ require('postcss-style-docs'), | ||
require('autoprefixer') | ||
] | ||
/** @docs Make it pop */ | ||
.something-fancy--pop { | ||
background: papayawhip; | ||
} | ||
`; | ||
const { css, messages } = await postcss([ | ||
styleDocsPlugin() | ||
]).process(inputCSS, { from: undefined }); | ||
const { commentMap } = getDocsMessage(messages); | ||
console.log(conmentMap.size); // 2 | ||
console.log(commentMap.get('.something-fancy')); // 'We're doing something really fancy and our users are going to love it' | ||
console.log(commentMap.get('.something-fancy--pop')); // 'Make it pop' | ||
``` | ||
[official docs]: https://github.com/postcss/postcss#usage |
13785
68