Skip to content

Commit

Permalink
fold long variable default values, fix mitmproxy#507
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Feb 19, 2023
1 parent dd3637d commit 77d5081
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- 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!
- 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.

0 comments on commit 77d5081

Please sign in to comment.