From 1128f4e22fbfa500d45545338c6e72ac30cf39f4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 17 Apr 2021 22:28:57 +0800 Subject: [PATCH] doc/_ext: render more fields in an option * print "enum_value" as a list * print "note" and "warning" Signed-off-by: Kefu Chai --- doc/_ext/ceph_confval.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/_ext/ceph_confval.py b/doc/_ext/ceph_confval.py index 98beebe5cf531..8899542306482 100644 --- a/doc/_ext/ceph_confval.py +++ b/doc/_ext/ceph_confval.py @@ -38,6 +38,26 @@ TEMPLATE = ''' :default: ``{{ default }}`` {%- endif -%} {%- endif %} +{%- if opt.enum_values %} + :valid choices:{% for enum_value in opt.enum_values -%} +{{" -" | indent(18, not loop.first) }} {{ enum_value | literal }} +{% endfor %} +{%- endif %} +{%- if opt.min is defined and opt.max is defined %} + :allowed range: ``[{{ opt.min }}, {{ opt.max }}]`` +{%- elif opt.min is defined %} + :min: ``{{ opt.min }}`` +{%- elif opt.max is defined %} + :max: ``{{ opt.max }}`` +{%- endif %} +{% if opt.note %} + .. note:: + {{ opt.note }} +{%- endif -%} +{%- if opt.warning %} + .. warning:: + {{ opt.warning }} +{%- endif %} ''' @@ -101,11 +121,19 @@ def readable_num(value: str, typ: str) -> str: raise e +def literal(name) -> str: + if name: + return f'``{name}``' + else: + return f'' + + def jinja_template() -> jinja2.Template: env = jinja2.Environment() env.filters['eval_size'] = eval_size env.filters['readable_duration'] = readable_duration env.filters['readable_num'] = readable_num + env.filters['literal'] = literal return env.from_string(TEMPLATE) -- 2.39.5