react-docgen-markdown-renderer
react-docgen-markdown-renderer copied to clipboard
Extend or expose handlebars instance
Hi! thanks for this generator, I'm using it in my project, and is working fine!
I would like to change the template in order to skip properties that have @ignore on the description, however I found handlebarsjs a little limited for this task (is the first time I use this template system), so I thought that adding handlebars-helpers would help in my case. However, I would need that you expose the handlebars instance to do that, or a way to pass my own handlebars via constructor. What do you recommend?
That was my first time with a templating system so I looked for something simple with some flexibility (didn't need much here since this template isn't that complex IMO), and I figured handlebars was a good choice. So I actually didn't knew about handlebars-helpers which is really cool!
Regarding your issue, it depends on react-docgen
to generate it (the ignore annotation) in their AST (not sure it does that right now) and only then we can do something about it (by exposing the handlebars instance/internally implementing/something else).
But for your case I think it's a bit of an overkill to add handlebars-helpers, ignoring a prop might actually be a common pattern so I'd implement this internally as part of the custom helpers.
Unfortunately, I don't have any time to work on this for a while, if you want you can submit a PR and I'd be happy to take a look at it :)
I totally agree with you, handlebars-helpers it is an overkill! 😄
Due to my 'urgent needs' I ended up copying index.js
and modifying it like this:
4a5,7
> const helpers = require('handlebars-helpers')({
> handlebars: handlebars
> });
28c31
< handlebars.registerPartial('union', 'Union<{{#with (typeObject this)}}{{#each value}}{{> (typePartial this) this}}{{#unless @last}}|{{/unless}}{{/each}}{{/with}}>');
---
> handlebars.registerPartial('union', 'Union<{{#with (typeObject this)}}{{#each value}}{{> (typePartial this) this}}{{#unless @last}} ∨ {{/unless}}{{/each}}{{/with}}>');
You might notice that I also changed the |
on the Union with an ∨
due to a limitation on gitlab markdown renderer that basically will mess-up the table, event when the pipe is inside a code limiter.
Finally, my template was changed to skip props with @ignore on it.
prop | type | default | required | description
---- | :----: | :-------: | :--------: | -----------
{{#each props}}
{{#contains this.description "@ignore"}}
{{else}}
**{{@key}}** | \`{{> (typePartial this) this}}\` | {{#if this.defaultValue}}\`{{{this.defaultValue}}}\`{{/if}} | {{#if this.required}}:white_check_mark:{{else}}:x:{{/if}} | {{#if this.description}}{{{this.description}}}{{/if}}
{{/contains}}
{{/each}}
I'll try to submit a proper PR for a custom helper to ignore properties as you suggested!