Skip to content

Commit 45a082d

Browse files
chore(docs): reformat configuration page (#4417) (#4428)
The large table didn't handle large descriptions or default values very well. Especially if the values were code blocks since they do not overflow. This change introduces a helper directive that will provide a consistent formatting from a list of configuration options. The reason we went with custom directive approach is the formatting of the configuration options can be changed at any time without needing to reformat each option individually. The input to the directive is a YAML format of: ```yaml OPTION_NAME: type: <type> default: <default> description: <description> ``` If `type`is not provided then `String` is used. If `default` is not provided then `(no value)` is used. `description` **must** be provided. If the value of `default` or `description` contains any special characters then a multi-line YAML block must be used. ```yaml description: | ``inline code block`` ``` The values of `type`, `default`, and `description` may contain rST formatted text. Co-authored-by: Kyle Verhoog <[email protected]> (cherry picked from commit a0eb79a) Co-authored-by: Brett Langdon <[email protected]>
1 parent 7aed6d4 commit 45a082d

File tree

2 files changed

+408
-374
lines changed

2 files changed

+408
-374
lines changed

docs/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,60 @@ def run(self):
673673
return node.children
674674

675675

676+
class DDTraceConfigurationOptionsDirective(rst.Directive):
677+
r"""
678+
Directive class to handle ``.. ddtrace-configuration-options::`` directive.
679+
680+
For example::
681+
682+
.. ddtrace-configuration-options::
683+
"""
684+
685+
has_content = True
686+
687+
def run(self):
688+
options = yaml.load("\n".join(self.content), Loader=yaml.CLoader)
689+
690+
results = statemachine.ViewList()
691+
for var_name, value in options.items():
692+
skip_label = value.get("skip_label") == "true"
693+
var_label = var_name.lower().replace("_", "-")
694+
var_description = value["description"]
695+
var_type = value.get("type") or "String"
696+
var_default = value.get("default") or "(no value)"
697+
var_version_added = value.get("version_added")
698+
699+
if not skip_label:
700+
results.append(".. _`{}`:".format(var_label), "", 0)
701+
results.append("", "", 0)
702+
results.append(".. py:data:: {}".format(var_name), "", 0)
703+
results.append("", "", 0)
704+
for line in var_description.splitlines():
705+
results.append(" " + line.lstrip(), "", 0)
706+
707+
results.append("", "", 0)
708+
results.append(" **Type**: {}".format(var_type), "", 0)
709+
results.append("", "", 0)
710+
results.append(" **Default**: {}".format(var_default), "", 0)
711+
results.append("", "", 0)
712+
713+
if var_version_added:
714+
for version, note in var_version_added.items():
715+
if note:
716+
results.append(" *Changed in version {}*: {}".format(version, note), "", 0)
717+
else:
718+
results.append(" *New in version {}.*".format(version), "", 0)
719+
results.append("", "", 0)
720+
721+
# Generate the RST nodes to return for rendering
722+
node = nodes.section()
723+
node.document = self.state.document
724+
self.state.nested_parse(results, 0, node)
725+
return node.children
726+
727+
676728
def setup(app):
677729
app.add_directive("ddtrace-release-notes", DDTraceReleaseNotesDirective)
730+
app.add_directive("ddtrace-configuration-options", DDTraceConfigurationOptionsDirective)
678731
metadata_dict = {"version": "1.0.0", "parallel_read_safe": True}
679732
return metadata_dict

0 commit comments

Comments
 (0)