Skip to content

fix: redner optional toggle fields when exists #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2022
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
24 changes: 20 additions & 4 deletions code_annotations/contrib/sphinx/extensions/featuretoggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def iter_nodes(self):
toggle_default_value = toggle.get(".. toggle_default:", "Not defined")
toggle_default_node = nodes.literal(text=quote_value(toggle_default_value))
toggle_section = nodes.section("", ids=[f"featuretoggle-{toggle_name}"])
toggle_section += nodes.title(text=toggle_name)
toggle_section += nodes.paragraph("", "Default: ", toggle_default_node)
toggle_section += nodes.title(text=toggle_name, ids=[f"name-{toggle_name}"])
toggle_section += nodes.paragraph(
"", "Default: ", toggle_default_node, ids=[f"default-{toggle_name}"]
)
toggle_section += nodes.paragraph(
"",
"Source: ",
Expand All @@ -90,14 +92,28 @@ def iter_nodes(self):
toggle["line_number"],
),
),
ids=[f"source-{toggle_name}"],
)
toggle_section += nodes.paragraph(
text=toggle.get(".. toggle_description:", "")
text=f'Desc: {toggle.get(".. toggle_description:", "NaN")}',
ids=[f"description-{toggle_name}"],
)
if toggle.get(".. toggle_warning:") not in (None, "None", "n/a", "N/A"):
toggle_section += nodes.warning(
"", nodes.paragraph("", toggle[".. toggle_warning:"])
"", nodes.paragraph("", toggle[".. toggle_warning:"]), ids=[f"warning-{toggle_name}"]
)
optional_attrs = [
"creation_date",
"target_removal_date",
"implementation",
"use_cases",
]
for opt in optional_attrs:
if toggle.get(f".. toggle_{opt}:") not in (None, "None", "n/a", "N/A"):
toggle_section += nodes.paragraph(
text=f'{opt.title().replace("_"," ")}: {toggle[f".. toggle_{opt}:"]}',
ids=[f"{opt}-{toggle_name}"],
)
yield toggle_section


Expand Down
26 changes: 19 additions & 7 deletions code_annotations/contrib/sphinx/extensions/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def find_settings(source_path):
Return:
settings (dict): Django settings indexed by name.
"""
return find_annotations(source_path, SETTING_ANNOTATIONS_CONFIG_PATH, ".. setting_name:")
return find_annotations(
source_path, SETTING_ANNOTATIONS_CONFIG_PATH, ".. setting_name:"
)


class Settings(SphinxDirective):
Expand Down Expand Up @@ -72,7 +74,9 @@ def iter_nodes(self):
source_path = os.path.join(self.env.config.settings_source_path, folder_path)
settings = find_settings(source_path)
# folder_path can point to a file or directory
root_folder = folder_path if os.path.isdir(source_path) else os.path.dirname(folder_path)
root_folder = (
folder_path if os.path.isdir(source_path) else os.path.dirname(folder_path)
)
for setting_name in sorted(settings):
setting = settings[setting_name]
# setting["filename"] is relative to the root_path
Expand All @@ -82,8 +86,10 @@ def iter_nodes(self):
text=quote_value(setting_default_value)
)
setting_section = nodes.section("", ids=[f"setting-{setting_name}"])
setting_section += nodes.title(text=setting_name)
setting_section += nodes.paragraph("", "Default: ", setting_default_node)
setting_section += nodes.title(text=setting_name, ids=[f"title-{setting_name}"])
setting_section += nodes.paragraph(
"", "Default: ", setting_default_node, ids=[f"default-{setting_name}"]
)
setting_section += nodes.paragraph(
"",
"Source: ",
Expand All @@ -98,13 +104,17 @@ def iter_nodes(self):
setting["line_number"],
),
),
ids=[f"source-{setting_name}"],
)
setting_section += nodes.paragraph(
text=setting.get(".. setting_description:", "")
text=setting.get(".. setting_description:", ""),
ids=[f"description-{setting_name}"],
)
if setting.get(".. setting_warning:") not in (None, "None", "n/a", "N/A"):
setting_section += nodes.warning(
"", nodes.paragraph("", setting[".. setting_warning:"])
"",
nodes.paragraph("", setting[".. setting_warning:"]),
ids=[f"warning-{setting_name}"],
)
yield setting_section

Expand All @@ -114,7 +124,9 @@ def setup(app):
Declare the Sphinx extension.
"""
app.add_config_value(
"settings_source_path", os.path.abspath(".."), "env",
"settings_source_path",
os.path.abspath(".."),
"env",
)
app.add_config_value("settings_repo_url", "", "env")
app.add_config_value("settings_repo_version", "master", "env")
Expand Down