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

save_html() now works correctly with components and pages with non-default theme values #823

Merged
merged 8 commits into from
Oct 11, 2023
Merged
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Imports:
base64enc,
cachem,
grDevices,
htmltools (>= 0.5.4.9000),
htmltools (>= 0.5.6.9001),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

main should already be on 0.5.6.9000 🙈

jquerylib (>= 0.1.3),
jsonlite,
lifecycle,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export(popover)
export(precompiled_css_path)
export(remove_all_fill)
export(run_with_themer)
export(save_html.bslib_fragment)
export(save_html.bslib_page)
export(showcase_bottom)
export(showcase_left_center)
export(showcase_top_right)
Expand Down
15 changes: 15 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ print.bslib_fragment <- function(x, ...) {
invisible(print(x, ...))
}

#' @export
save_html.bslib_fragment <- function(html, file, ...) {
html <- attr(html, "bslib_page")(html)
save_html(html, file, ...)
}

#' @rdname html-browse
#' @export
print.bslib_page <- function(x, ...) {
Expand All @@ -36,3 +42,12 @@ print.bslib_page <- function(x, ...) {

invisible(NextMethod())
}

#' @export
save_html.bslib_page <- function(html, file, ...) {
old_theme <- bs_global_get()
bs_global_set(attr(html, "bs_theme", exact = TRUE))
on.exit(bs_global_set(old_theme), add = TRUE)

NextMethod()
}
Loading