-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #137: fix logic for inferring window title from Tag/TagList obj…
…ects
- Loading branch information
Showing
3 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
from htmltools import tags, Tag, TagChildArg | ||
from typing import Optional, Union | ||
import warnings | ||
|
||
from htmltools import ( | ||
tags, | ||
Tag, | ||
TagList, | ||
TagChildArg, | ||
TagChild, | ||
HTMLDependency, | ||
head_content, | ||
) | ||
|
||
from ..types import MISSING, MISSING_TYPE | ||
|
||
|
||
def shiny_input_label(id: str, label: TagChildArg = None) -> Tag: | ||
cls = "control-label" + ("" if label else " shiny-label-null") | ||
return tags.label(label, class_=cls, id=id + "-label", for_=id) | ||
|
||
|
||
def get_window_title( | ||
title: Optional[Union[str, Tag, TagList]], | ||
window_title: Union[str, MISSING_TYPE] = MISSING, | ||
) -> Optional[HTMLDependency]: | ||
if title is not None and isinstance(window_title, MISSING_TYPE): | ||
window_title = _find_child_strings(title) | ||
|
||
if isinstance(window_title, MISSING_TYPE): | ||
return None | ||
else: | ||
return head_content(tags.title(window_title)) | ||
|
||
|
||
def _find_child_strings(x: Union[Tag, TagList, TagChild]) -> str: | ||
if isinstance(x, Tag): | ||
x = x.children | ||
if isinstance(x, TagList): | ||
return " ".join([_find_child_strings(y) for y in x]) | ||
return x if isinstance(x, str) else "" |