2021-02-08 19:40:43 +03:00
# DSS
2012-08-24 01:29:57 +04:00
2021-02-11 15:18:40 +03:00
This is a fork of [DSS ](https://github.com/DSSORG/DSS ).
2021-02-08 19:40:43 +03:00
**DSS**, Documented Style Sheets, is a comment styleguide and parser for CSS, LESS, SASS and SCSS code.
2012-08-24 01:29:57 +04:00
2013-03-18 08:42:54 +04:00
## Generating Documentation
2021-02-08 19:40:43 +03:00
In most cases, you will want to include the **DSS** parser in a build step that will generate documentation files automatically.
2013-03-18 08:42:54 +04:00
## Parser Example
#### Example Comment Block
2012-08-24 01:29:57 +04:00
2013-03-02 17:09:49 +04:00
```css
/**
2021-02-10 15:16:39 +03:00
* @name Button
* @description Your standard form button.
*
* @state :hover - Highlights when hovering.
* @state :disabled - Dims the button when disabled.
* @state .primary - Indicates button is the primary action.
* @state .smaller - A smaller button.
*
* @example
* < span >
* < button > This is a button</ button >
* </ span >
*
* @deprecated 123.321
* @deprecatedDescription This is deprecated.
*
* @group Buttons
* @type Color
* @subtype Text-Color
* @key $button-bg
*
* @param {string} par1 - ParmOne description.
* @param {function} par2 - ParamTwo description.
* @returns {number} - Return description.
*/
2021-02-08 19:40:43 +03:00
```
2013-03-15 20:18:14 +04:00
#### or
```scss
2021-02-08 19:40:43 +03:00
/// @name Button
/// @description Your standard form button.
///
/// @state :hover - Highlights when hovering.
/// @state :disabled - Dims the button when disabled.
/// @state .primary - Indicates button is the primary action.
/// @state .smaller - A smaller button.
///
2021-02-10 13:50:22 +03:00
/// @example
2021-02-08 19:40:43 +03:00
/// < span >
/// < button > This is a button< / button >
/// < / span >
///
/// @deprecated 123.321
/// @deprecatedDescription This is deprecated.
///
/// @group Buttons
/// @type Color
/// @subtype Text-Color
/// @key $button-bg
///
/// @param {string} par1 - ParmOne description.
/// @param {function} par2 - ParamTwo description.
/// @returns {number} - Return description.
///
```
## Basic Usage
2013-03-18 08:42:54 +04:00
2015-05-06 00:20:20 +03:00
```javascript
2015-05-06 00:19:19 +03:00
// Require/read a file
2021-02-08 19:51:26 +03:00
const fs = require('fs');
2021-02-08 19:40:43 +03:00
const dss = require('dss');
const file = fs.readFileSync('styles.scss');
2015-05-06 00:19:19 +03:00
// Run DSS Parser
2021-02-08 19:40:43 +03:00
dss.parse(file, {}, (parsed) => {
2021-02-15 18:47:56 +03:00
console.log(parsed.blocks);
2015-05-06 00:19:19 +03:00
});
2021-02-08 19:40:43 +03:00
```
2013-03-18 08:42:54 +04:00
#### Example Generated Object
2013-03-15 20:18:14 +04:00
2014-02-26 20:41:40 +04:00
```json
2021-02-08 19:51:26 +03:00
[{
2021-02-15 18:47:56 +03:00
"name": "Button",
"description": "Your standard form button.",
"state": [
{
"name": ":hover",
"escaped": "pseudo-class-hover",
"description": "Highlights when hovering."
},
{
"name": ":disabled",
"escaped": "pseudo-class-disabled",
"description": "Dims the button when disabled."
},
{
"name": ".primary",
"escaped": "primary",
"description": "Indicates button is the primary action."
},
{
"name": ".smaller",
"escaped": "smaller",
"description": "A smaller button."
}
],
"example": {
"example": " < span > \n < button > This is a button</ button > \n </ span > ",
"escaped": " < span> \n < button> This is a button< /button> \n < /span> "
2013-03-15 20:18:14 +04:00
},
2021-02-15 18:47:56 +03:00
"deprecated": "123.321",
"deprecatedDescription": "This is deprecated.",
"group": "buttons",
"type": "color",
"subtype": "text-color",
"key": "$button-bg",
"param": [
{
"type": "{string}",
"name": "par1",
"description": "ParmOne description."
},
{
"type": "{function}",
"name": "par2",
"description": "ParmTwo description."
}
],
"returns": {
"type": "{number}",
"name": null,
"description": "Return description."
2021-02-08 19:40:43 +03:00
}
2021-02-08 19:51:26 +03:00
}]
2021-02-08 19:40:43 +03:00
```
## Parsers Specifics
2021-02-10 13:50:22 +03:00
1. Only the `description` and `example` parsers allow usage of multi-line comments.
2021-02-11 15:18:40 +03:00
1. If a comment block starts without an annotation, the parser sets this text as `description` . However, if a `description` annotation is available, the parser overrides the non-annotation one.
1. If more than one `example` is provided, the parser returns an array of examples.
2021-02-08 19:40:43 +03:00
1. The `state` and `param` parsers are returning an array of all the relevant annotations.
1. If not defined, the parser tries to assume the `type` and `key` values based on the next line.
1. The `group` , `type` , and `subtype` parsers convert the string annotation to lowercase letters.
2013-03-18 08:42:54 +04:00
2021-02-11 15:18:40 +03:00
## Parser Aliases
The parser aliases set their value in the `key` of the main parser in the output `JSON` .
**DSS**, by default, includes the following `alias` - `parser` pairs:
1. `return` - `returns`
1. `markup` - `example`
2013-03-18 08:42:54 +04:00
## Modifying Parsers
2021-02-10 13:50:22 +03:00
**DSS**, by default, includes the `name` , `description` , `state` , `example` , `deprecated` , `deprecatedDescription` , `group` , `type` , `subtype` , `key` , `param` , and `returns` parsers of a comment block. You can add to or override these default parsers using the following:
2013-03-18 08:42:54 +04:00
```javascript
// Matches @link
2021-02-08 19:40:43 +03:00
dss.parser('link', (i, line, block, file) => {
2021-02-15 18:47:56 +03:00
// Replace link with HTML wrapped version
const exp = /(b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.; ]*[-A-Z0-9+&@#/%=~_|])/ig;
2014-01-07 08:25:19 +04:00
2021-02-15 18:47:56 +03:00
return line.replace(exp, "< a href = '$1' > $1< / a > ");
2021-02-08 19:40:43 +03:00
});
```
2014-01-07 08:25:19 +04:00
2021-02-08 19:40:43 +03:00
```javascript
// Matches @version
dss.parser('version', (i, line, block, file) => {
2021-02-15 18:47:56 +03:00
return line;
2021-02-08 19:40:43 +03:00
});
```