Skip to content
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

fold long variable default values, fix #507 #511

Merged
merged 2 commits into from
Feb 19, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- pdoc now skips constructors if they neither have a docstring nor any parameters. This improves display
of classes that are not meant to be instantiated manually, for example when using PyO3.
([#510](https://github.com/mitmproxy/pdoc/pull/510), @mhils)
- Automatically fold a variable's default value if it exceeds 100 characters.
Feedback on this cutoff is welcome!
([#511](https://github.com/mitmproxy/pdoc/pull/511), @mhils)
- Add a workaround to support inherited TypedDicts.
([#504](https://github.com/mitmproxy/pdoc/issues/504), @mhils)
- `Variable.default_value_str` does not include the ` = ` prefix anymore. It will now emit a warning and return
Expand Down
28 changes: 28 additions & 0 deletions pdoc/templates/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when
}

.pdoc .pdoc-button {
cursor: pointer;
display: inline-block;
border: solid black 1px;
border-radius: 2px;
Expand Down Expand Up @@ -332,6 +333,33 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when
color: var(--annotation);
}

/* Show/Hide buttons for long default values */
.pdoc .view-value-toggle-state,
.pdoc .view-value-toggle-state ~ .default_value {
display: none;
}
.pdoc .view-value-toggle-state:checked ~ .default_value {
display: inherit;
}
.pdoc .view-value-button {
font-size: .5rem;
vertical-align: middle;
border-style: dashed;
margin-top: -0.1rem;
}
.pdoc .view-value-button:hover {
background: white;
}
.pdoc .view-value-button::before {
content: "show";
text-align: center;
width: 2.2em;
display: inline-block;
}
.pdoc .view-value-toggle-state:checked ~ .view-value-button::before {
content: "hide";
}

/* Inherited Members */
.pdoc .inherited {
margin-left: 2rem;
Expand Down
9 changes: 7 additions & 2 deletions pdoc/templates/default/module.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an
{%- endif -%}
{% enddefaultmacro %}
{% defaultmacro default_value(var) -%}
{%- if var.default_value_str -%}
<span class="default_value"> = {{ var.default_value_str | escape | linkify }}</span>
{%- if var.default_value_str %}
=
{% if var.default_value_str | length > 100 -%}
<input id="{{ var.qualname }}-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
<label class="view-value-button pdoc-button" for="{{ var.qualname }}-view-value"></label>
{%- endif -%}
<span class="default_value">{{ var.default_value_str | escape | linkify }}</span>
{%- endif -%}
{% enddefaultmacro %}
{% defaultmacro annotation(var) %}
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/demo.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/demo_eager.html

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions test/testdata/demo_long.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/demopackage.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/testdata/demopackage_dir.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_customtemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_darkmode.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_mkdocs.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions test/testdata/flavors_google.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions test/testdata/flavors_numpy.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/flavors_rst.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/math_demo.html

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions test/testdata/misc.html

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions test/testdata/misc_py310.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py311.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py39.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/testdata/render_options.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/top_level_reimports.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions test/testdata/type_checking_imports.html

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions test/testdata/type_stub.html

Large diffs are not rendered by default.