Skip to content

Commit

Permalink
Close #477. save_html() now works correctly with components and pages…
Browse files Browse the repository at this point in the history
… with non-default theme values
  • Loading branch information
cpsievert committed Oct 5, 2023
1 parent bee0b80 commit d18c684
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ S3method(print,bslib_fragment)
S3method(print,bslib_page)
S3method(print,bslib_showcase_layout)
S3method(print,bslib_value_box_theme)
S3method(save_html,bslib_fragment)
S3method(save_html,bslib_page)
export(accordion)
export(accordion_panel)
export(accordion_panel_close)
Expand Down
15 changes: 15 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ print.bslib_page <- function(x, ...) {

invisible(NextMethod())
}

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

#' @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()
}

0 comments on commit d18c684

Please sign in to comment.