Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ You can change some settings in the `styleguide.config.js` file in your project
};
```

* **`propsParser`**<br>
Type: `Function`, optional<br>
Function that allows you to override the mechanism used to parse props from a source file. Default mechanism is using
[react-docgen](https://github.com/reactjs/react-docgen) to parse props.

```javascript
module.exports = {
// ...
propsParser: function(filePath, source) {
return require('react-docgen').parse(source);
}
}
```

* **`resolver`**<br>
Type: `Function`, optional<br>
Function that allows you to override the mechanism used to identify classes/components to analyze. Default
Expand Down
9 changes: 7 additions & 2 deletions loaders/props.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ var requirePlaceholder = '<%{#require#}%>';
module.exports = function (source) {
this.cacheable && this.cacheable();

var defaultPropsParser = function(filePath, source) {
return reactDocs.parse(source, config.resolver, config.handlers);
};

var jsonProps;
try {
var props = reactDocs.parse(source, config.resolver, config.handlers);
var propsParser = config.propsParser || defaultPropsParser;
var props = propsParser(this.request.split('!').pop(), source);

jsonProps = (isArray(props) ? props : [props]).map(function(doc) {
if (doc.description) {
Expand All @@ -25,7 +30,7 @@ module.exports = function (source) {
}

return JSON.stringify(doc).replace(
'"' + requirePlaceholder + '"',
'"' + requirePlaceholder + '"',
doc.doclets.example && 'require(' + JSON.stringify('examples!' + doc.doclets.example) + ')'
);
});
Expand Down