Skip to content

feat: Add include_bootstrap_css()#1282

Closed
gadenbuie wants to merge 5 commits intomainfrom
feat/include-bootstrap-css
Closed

feat: Add include_bootstrap_css()#1282
gadenbuie wants to merge 5 commits intomainfrom
feat/include-bootstrap-css

Conversation

@gadenbuie
Copy link
Collaborator

Closes #1270

Comment on lines +51 to +59
def bootstrap_deps_suppress(
parts: list[Literal["css", "js", "meta"]]
) -> list[HTMLDependency]:
bs_v_suppressed = str(bootstrap_version) + ".9999"

return [
HTMLDependency(name=f"bootstrap-{part}", version=bs_v_suppressed)
for part in parts
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small thing, but I think I'd prefer this to be more generic, like htmltools::supressDependencies()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that not exist in py-htmltools? We could add it there.

There might still be some value in this helper function, though. This function encapsulates both the Bootstrap version and the naming pattern we use. Also, suppressDependencies() uses version="9999", but I'm trying to be more careful here and am only suppressing the version used by Shiny. So we'd either have to update the API of suppressDependencies() or we'd still use this version.

OTOH, we could drop this function and other packages could use something like htmltools.suppress_dependency() instead. As we can see from the shinyswatch experience though, that increases the strength of coupling between shiny and the external packages. If we change how the Bootstrap dependency is structured, we'd need to change third party code as well. If we use this (not publicly advertised) helper function though, we can change the implementation in Shiny without breaking external code or having to update across several packages at once

Copy link
Collaborator

@cpsievert cpsievert Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, now I see that your intention is for {shinyswatch} to also make use of this function. I suppose that's good enough reason for keeping this as is so that shinyswatch doesn't have to know how the dependency names are setup.

Also, let's add a comment about shinyswatch using this?

}

bootstrap_css = HTMLDependency(
name="bootstrap-css",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider pulling the names out into variables so that it's more obvious that bootstrap_deps() and bootstrap_deps_suppress() have shared logic


@add_example()
def include_bootstrap_css(
theme: Path | str | HTMLDependency,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we could keep things a lot simpler if we dropped support for this type. I'm not entirely sure we can get away with that though

Suggested change
theme: Path | str | HTMLDependency,
theme: Path | str,

Comment on lines +248 to +251
return [
*bootstrap_deps_suppress(["css"]),
theme_dep,
]
Copy link
Collaborator

@cpsievert cpsievert Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realize that this'll be problematic for multiple calls to include_bootstrap_css(). Maybe we could work around that by always returning the full Bootstrap dependency, but with the version incremented by f".counter()" each time?

version=theme.version,
)

if hasattr(theme, "bs_version"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of my concerns about complexity here could go away if we decided we didn't need to introduce yet another representation of the version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users or third-party packages to replace Bootstrap CSS

2 participants