Skip to content

Commit

Permalink
Add support for multiline json in tables
Browse files Browse the repository at this point in the history
- Since MD syntax does not really support it so I've created
table using html table syntax and it seems to render perfectly.

Pending items
--------------

- rst and html templates.

Fixes rapidsai#17 rapidsai#24
  • Loading branch information
raul1991 authored and Rahul Bawa committed Nov 10, 2020
1 parent def0b7b commit c3fe628
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
13 changes: 10 additions & 3 deletions frigate/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import tempfile
import shutil
import subprocess

import datetime
from json import JSONEncoder
from jinja2 import Environment, FileSystemLoader
from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap
Expand Down Expand Up @@ -184,6 +185,12 @@ def clean_comment(comment):
return comment.strip("# ")


class DateTimeEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (datetime.date, datetime.datetime)):
return obj.isoformat()


def traverse(tree, root=None):
"""Iterate over a tree of configuration and extract all information.
Expand Down Expand Up @@ -230,10 +237,10 @@ def traverse(tree, root=None):
if key in tree.ca.items:
comment = get_comment(tree, key)
param = ".".join(root + [key])
yield [param, comment, json.dumps(default)]
yield [param, comment, json.dumps(default, indent=4, sort_keys=True, cls=DateTimeEncoder)]


def gen(chartdir, output_format, credits=True, deps=True):
def gen(chartdir, output_format, credits=True, deps=True, update=True):
"""Generate documentation for a Helm chart.
Generate documentation for a Helm chart given the path to a chart and a
Expand Down
2 changes: 1 addition & 1 deletion frigate/templates/html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<tr>
<td><code>{{ param }}</code></td>
<td>{{ comment }}</td>
<td><code>{{ default }}</code></td>
<td><pre>{{ default }}</pre></td>
</tr>
{% endfor -%}
</table>
Expand Down
35 changes: 29 additions & 6 deletions frigate/templates/markdown.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,37 @@
## Configuration

The following table lists the configurable parameters of the {{ name | capitalize }} chart and their default values.

| Parameter | Description | Default |
| ------------------------ | ----------------------- | -------------- |
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
{% for (param, comment, default) in values -%}
| `{{ param }}` | {{ comment }} | `{{ default }}` |
<tr>
<td>{{ param }}</td>
<td>{{ comment }}</td>
<td>
{% if "\n" in default %}
```json

{{ default }}

```
{% else %}

{{ default }}

{% endif %}
</td>
</tr>
{% endfor -%}
</tbody>
</table>
{%- endblock %}

{% block footnotes -%}
{{ footnotes }}
{% endblock -%}
Expand All @@ -32,4 +55,4 @@ The following table lists the configurable parameters of the {{ name | capitaliz
---
_Documentation generated by [Frigate](https://frigate.readthedocs.io)._
{%- endif -%}
{%- endblock %}
{%- endblock %}

0 comments on commit c3fe628

Please sign in to comment.