Skip to content

Commit

Permalink
Create a button to link a Page Builder class to its visual element doc (
Browse files Browse the repository at this point in the history
#1165)

* [element_type] -> element type in Page Builder classes doc
  • Loading branch information
FabienLelaquais committed Oct 14, 2024
1 parent 6bff97d commit 968749f
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 111 deletions.
1 change: 1 addition & 0 deletions taipy_theme/assets/images/element-doc-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 22 additions & 5 deletions taipy_theme/assets/stylesheets/avaiga.css
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,28 @@ div.tp-gcs {
margin-right: 0;
text-align: right;
a::before {
content: '';
display: inline-block;
content: url("../images/github-mark-white.svg");
width: 1.5em;
height: 1.5em;
content: '';
display: inline-block;
content: url("../images/github-mark-white.svg");
width: 1.5em;
height: 1.5em;
}
}
/* ---------- Button from Page Builder class to element documentation ---------- */
/* ved = Visual Element Documentation */
div.tp-ved {
margin-left: auto;
margin-right: 0;
text-align: right;
& > .tp-btn {
padding-left: 0.4rem;
}
a::before {
content: '';
display: inline-block;
content: url("../images/element-doc-white.svg");
width: 1.5em;
height: 1.5em;
}
}
/* ---------- ---------- ---------- Navigation buttons ---------- ---------- ---------- */
Expand Down
3 changes: 1 addition & 2 deletions tools/_setup_generation/step_viselements.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ def build_doc(property: str, desc, indent: int):
class [element_type]({base_class}):
\"\"\"[short_doc]
This class represents the [control_or_block] documented in the [element_md_page] section.
data-viselement: [control_or_block] [element_md_page]
\"\"\"
_ELEMENT_NAME: str
def __init__(self, [arguments]) -> None:
\"\"\"Create a new `[element_type]` element.
Expand Down
213 changes: 109 additions & 104 deletions tools/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,76 +609,120 @@ def rewrite_title(s: str, start: int, end: int) -> str:
html_content,
)

# Page Builder class?
if re.search(
r"([/\\])pkg_gui\1pkg_builder\1\w+\1index.html$", filename
) and re.search(r"<title>\w+\s+class\s", html_content):
# Replace, in signature, styled strings by None and comment
new_content = ""
last_location = 0
# Find signatures
for s_m in re.finditer(
r"""<div\s+class="doc-signature
(.*?)
div>""",
html_content,
re.X | re.S,
):
new_content += html_content[last_location : s_m.start()]
last_location = s_m.end()
signature = s_m[0]
sig_content = ""
sig_location = 0
# Within those signatures, find ill-defined default values
# Page Builder class?
m = re.search(r"([/\\])pkg_gui\1pkg_builder\1(\w+)\1index.html$", filename)
if m and re.search(r"<title>\w+\s+class\s", html_content):
element_type = m[2]
# Replace, in signature, styled strings by None and comment
new_content = ""
last_location = 0
# Find signatures
for s_m in re.finditer(
r"""<div\s+class="doc-signature
(.*?)
div>""",
html_content,
re.X | re.S,
):
new_content += html_content[
last_location : s_m.start()
]
last_location = s_m.end()
signature = s_m[0]
sig_content = ""
sig_location = 0
# Within those signatures, find ill-defined default values
for p_m in re.finditer(
r"""<span\s+class="s2">
&quot;(&lt;.*?)&quot;
</span>
(<span\s+class="p">,</span>)?""",
signature,
re.X | re.S,
):
sig_content += signature[
sig_location : p_m.start()
]
# Style ill-defined default values in a comment
comment = re.sub(
r"&lt;(/)?(i|tt)&gt;", r"<\1\2>", p_m[1]
)
sig_content += f'<span class="kc">None</span>{p_m[2]}<span class="sd"> # {comment}</span>'
sig_location = p_m.end()
if sig_location:
signature = (
sig_content + signature[sig_location:]
)
new_content += signature
if last_location:
html_content = (
new_content + html_content[last_location:]
)
# Properly style default values, in parameters description
# Fix issue with indexed and dynamic properties
new_content = ""
last_location = 0
# Find parameters type and default value
for p_m in re.finditer(
r"""<span\s+class="s2">
&quot;(&lt;.*?)&quot;
</span>
(<span\s+class="p">,</span>)?""",
signature,
r"""<tr\s+class="doc-section-item">
\s+<td.*?td> # name
\s+<td>\s+<code>\s*(.*?)\s*</code>\s*</td> # type
\s+<td.*?td> # doc
\s+<td>\s+<code>\s*(.*?)\s*</code>\s*</td> # default value
\s+</tr>""",
html_content,
re.X | re.S,
):
sig_content += signature[sig_location : p_m.start()]
# Style ill-defined default values in a comment
comment = re.sub(
r"&lt;(/)?(i|tt)&gt;", r"<\1\2>", p_m[1]
p_type = p_m[1]
if t_m := re.match(
r"(dynamic|indexed)\((.*)", p_type
):
p_type = f"{t_m[2]}<br/><small><i>{t_m[1]}</i></small>"
# A property can be both dynamic and indexed
if t_m := re.match(
r"(dynamic|indexed)\((.*)", p_type
):
p_type = f"{t_m[2]}<br/><small><i>{t_m[1]}</i></small>"
p_def_value = re.sub(
r"&\#39;(.*?)&\#39;", r"\1", p_m[2]
)
sig_content += f'<span class="kc">None</span>{p_m[2]}<span class="sd"> # {comment}</span>'
sig_location = p_m.end()
if sig_location:
signature = sig_content + signature[sig_location:]
new_content += signature
if last_location:
html_content = (
new_content + html_content[last_location:]
)
# Properly style default values, in parameters description
new_content = ""
last_location = 0
# Find parameters default value
for p_m in re.finditer(
r"""<tr\s+class="doc-section-item">
(?:\s+<td.*?td>){3}
\s+<td>\s+(<code>&\#39;&lt;.*?)\s+</td>
\s+</tr>""",
html_content,
re.X | re.S,
):
new_content += html_content[
last_location : p_m.start(1)
]
default_value = re.sub(
r"<code>&\#39;(.*?)&\#39;</code>", r"\1", p_m[1]
)
default_value = re.sub(
r"&lt;(/)?(i|tt)&gt;", r"<\1\2>", default_value
)
new_content += default_value
last_location = p_m.end(1)
if last_location:
html_content = (
new_content + html_content[last_location:]
p_def_value = re.sub(
r"&lt;(/)?(i|tt)&gt;", r"<\1\2>", p_def_value
)
new_content += (
html_content[last_location : p_m.start(1)]
+ p_type
+ re.sub(
r"(?<=<code>taipy-)\[element_type\](?=</code>)",
element_type,
html_content[p_m.end(1) : p_m.start(2)],
re.X | re.S,
)
+ p_def_value
)
last_location = p_m.end(2)
if last_location:
html_content = (
new_content + html_content[last_location:]
)
# Remove "Bases" information
html_content = re.sub(
r"<p\s+class=\"doc\s+doc-class-bases\">.*?</p>",
"",
html_content,
flags=re.S,
)
# Add link to element documentation page
if m := re.search(
r"<p>data-viselement:\s+(\w+)\s+<a\s+href=\"(.*)(?:\".*?</p>)",
html_content,
):
html_content = (
html_content[: m.start()]
+ f"""<div class="tp-ved"><a class="tp-btn tp-btn--alpha" href="{m[2]}">
See full documentation and examples for this {m[1]}</a></div>"""
+ html_content[m.end() :]
)

# Processing for visual element pages:
# - Remove <tt> from title
Expand Down Expand Up @@ -746,45 +790,6 @@ def rewrite_title(s: str, start: int, end: int) -> str:
+ article_match.group(2)
+ html_content[article_match.end() :]
)
# Processing for the page builder API:
fn_match = re.search(
r"(/|\\)reference\1taipy\.gui\.builder.(.*?)\1index.html",
filename,
)
if fn_match is not None:
# Default value of properties appear as "dynamic(type" as "indexed(type"
prop_re = re.compile(
r"<tr>\s*<td><code>.*?</code></td>"
+ r"\s*<td>\s*<code>(.*?)</code>\s*</td>\s*<td>",
re.S,
)
new_content = ""
last_location = 0
for prop in prop_re.finditer(html_content):
if default_value_re := re.match(
r"(dynamic|indexed)\((.*)", prop[1]
):
new_content += html_content[
last_location : prop.start(1)
]
new_content += f"{default_value_re[2]}<br/><small><i>{default_value_re[1]}</i></small>"
last_location = prop.end(1)
if last_location:
html_content = new_content + html_content[last_location:]
# '<i>default value</i>' -> <i>default value</i>
dv_re = re.compile(
r"&\#39;&lt;i&gt;(.*?)&lt;/i&gt;&\#39;", re.S
)
new_content = ""
last_location = 0
for dv in dv_re.finditer(html_content):
new_content += (
html_content[last_location : dv.start()]
+ f"<i>{dv[1]}</i>"
)
last_location = dv.end()
if last_location:
html_content = new_content + html_content[last_location:]

# Handle title and header in packages documentation file
def code(s: str) -> str:
Expand Down

0 comments on commit 968749f

Please sign in to comment.