-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Make ioslides_presentation() more themable via {bslib} and {sass} #2013
base: main
Are you sure you want to change the base?
Changes from all commits
3009659
116907c
50d178a
d0b53c2
7403afc
fd331ac
3e81227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,9 +19,12 @@ | |||||||||||||||
#' @param transition Speed of slide transitions. This can be "default", | ||||||||||||||||
#' "slower", "faster", or a numeric value with a number of seconds (e.g. 0.5). | ||||||||||||||||
#' @param analytics A Google analytics property ID. | ||||||||||||||||
#'@param smart Produce typographically correct output, converting straight | ||||||||||||||||
#' quotes to curly quotes, \code{---} to em-dashes, \code{--} to en-dashes, and | ||||||||||||||||
#' \code{...} to ellipses. | ||||||||||||||||
#' @param smart Produce typographically correct output, converting straight | ||||||||||||||||
#' quotes to curly quotes, \code{---} to em-dashes, \code{--} to en-dashes, and | ||||||||||||||||
#' \code{...} to ellipses. | ||||||||||||||||
#' @param theme a list of theming arguments (currently `bg`, `fg`, `primary`, | ||||||||||||||||
#' `success`, `warning`, `danger`, `base_font`, and `code_font` are supported, | ||||||||||||||||
#' see [bslib::bs_theme()] for more about these options) | ||||||||||||||||
#' @return R Markdown output format to pass to \code{\link{render}}. | ||||||||||||||||
#' @details | ||||||||||||||||
#' See the \href{https://bookdown.org/yihui/rmarkdown/ioslides-presentation.html}{ | ||||||||||||||||
|
@@ -248,6 +251,7 @@ ioslides_presentation <- function(number_sections = FALSE, | |||||||||||||||
md_extensions = NULL, | ||||||||||||||||
pandoc_args = NULL, | ||||||||||||||||
extra_dependencies = NULL, | ||||||||||||||||
theme = NULL, | ||||||||||||||||
...) { | ||||||||||||||||
|
||||||||||||||||
# base pandoc options for all output | ||||||||||||||||
|
@@ -289,9 +293,17 @@ ioslides_presentation <- function(number_sections = FALSE, | |||||||||||||||
template <- pkg_file("rmd/ioslides/default.html") | ||||||||||||||||
args <- c(args, "--template", pandoc_path_arg(template)) | ||||||||||||||||
|
||||||||||||||||
# html dependency for ioslides | ||||||||||||||||
extra_dependencies <- append(extra_dependencies, | ||||||||||||||||
list(html_dependency_ioslides())) | ||||||||||||||||
# Add ioslides HTML dependencies | ||||||||||||||||
# If bslib is relevant, we want to register a _deferred_ version of the CSS dependency so | ||||||||||||||||
# it can update in response to Shiny's session$setCurrentTheme() (e.g., bslib::bs_themer()) | ||||||||||||||||
# https://rstudio.github.io/bslib/articles/theming.html#dynamic-theming-in-shiny | ||||||||||||||||
theme <- resolve_theme(theme) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should provide a more specific handling / checking of the For example, using ioslides_presentation:
theme: cerulean will issue no warning or error. It will do nothing, so not harmful but some users could expect this to work as other formats. (even if the doc does not say so). Maybe we can check early and warn that will have not effect (or stop and say only bslib is supported so a list.
Suggested change
We could also modify the It could also be We would have for this format.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This does do something though -- it brings in Bootstrap! So, I don't think we want to introduce an error in this case -- I'm sure folks are relying on this functionality. |
||||||||||||||||
if (is_bs_theme(theme)) { | ||||||||||||||||
dynamic_ioslides <- bslib::bs_dependency_defer(html_dependency_ioslides) | ||||||||||||||||
theme <- bslib::bs_bundle(theme, sass::sass_layer(html_deps = dynamic_ioslides)) | ||||||||||||||||
} else { | ||||||||||||||||
extra_dependencies <- append(extra_dependencies, html_dependency_ioslides(theme)) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
# analytics | ||||||||||||||||
if (!is.null(analytics)) | ||||||||||||||||
|
@@ -453,14 +465,16 @@ ioslides_presentation <- function(number_sections = FALSE, | |||||||||||||||
mathjax = mathjax, | ||||||||||||||||
pandoc_args = pandoc_args, | ||||||||||||||||
extra_dependencies = extra_dependencies, | ||||||||||||||||
bootstrap_compatible = TRUE, ...)) | ||||||||||||||||
bootstrap_compatible = TRUE, theme = theme, ...)) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
html_dependency_ioslides <- function() { | ||||||||||||||||
htmlDependency( | ||||||||||||||||
name = "ioslides", | ||||||||||||||||
version = "13.5.1", | ||||||||||||||||
html_dependency_ioslides <- function(theme = NULL) { | ||||||||||||||||
name <- "ioslides" | ||||||||||||||||
version <- "13.5.1" | ||||||||||||||||
js <- htmlDependency( | ||||||||||||||||
name = paste0(name, "-js"), | ||||||||||||||||
version = version, | ||||||||||||||||
src = pkg_file("rmd/ioslides/ioslides-13.5.1"), | ||||||||||||||||
script = c( | ||||||||||||||||
"js/modernizr.custom.45394.js", | ||||||||||||||||
|
@@ -470,10 +484,43 @@ html_dependency_ioslides <- function() { | |||||||||||||||
"js/hammer.js", | ||||||||||||||||
"js/slide-controller.js", | ||||||||||||||||
"js/slide-deck.js" | ||||||||||||||||
), | ||||||||||||||||
stylesheet = c( | ||||||||||||||||
"fonts/fonts.css", | ||||||||||||||||
"theme/css/default.css", | ||||||||||||||||
"theme/css/phone.css") | ||||||||||||||||
) | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
theme <- resolve_theme(theme) | ||||||||||||||||
if (!is_bs_theme(theme)) { | ||||||||||||||||
Comment on lines
+490
to
+491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already doing this on the outside of the function. As Aim is just to avoid some duplication of logic in different places. |
||||||||||||||||
css <- htmlDependency( | ||||||||||||||||
name = paste0(name, "-css"), | ||||||||||||||||
version = version, | ||||||||||||||||
src = pkg_file("rmd/ioslides/ioslides-13.5.1"), | ||||||||||||||||
stylesheet = c( | ||||||||||||||||
"fonts/fonts.css", | ||||||||||||||||
"theme/css/default.css", | ||||||||||||||||
"theme/css/phone.css" | ||||||||||||||||
) | ||||||||||||||||
) | ||||||||||||||||
return(list(js, css)) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if ("3" %in% theme_version(theme)) { | ||||||||||||||||
stop("`ioslides_presentation()` is not compatible with Bootstrap 3 (use version = 4 or higher)") | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+505
to
+507
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this should be tested in the format function |
||||||||||||||||
io_file <- function(...) { | ||||||||||||||||
sass::sass_file(pkg_file("rmd/ioslides/ioslides-13.5.1", ...)) | ||||||||||||||||
} | ||||||||||||||||
css <- bslib::bs_dependency( | ||||||||||||||||
input = sass::sass_layer( | ||||||||||||||||
rules = list( | ||||||||||||||||
io_file("fonts/fonts.css"), | ||||||||||||||||
io_file("theme/css/default.scss"), | ||||||||||||||||
io_file("theme/css/phone.css") | ||||||||||||||||
), | ||||||||||||||||
file_attachments = c(fonts = pkg_file("rmd/ioslides/ioslides-13.5.1/fonts")) | ||||||||||||||||
), | ||||||||||||||||
theme = theme, | ||||||||||||||||
name = paste0(name, "-css"), | ||||||||||||||||
version = version, | ||||||||||||||||
cache_key_extra = packageVersion("rmarkdown") | ||||||||||||||||
) | ||||||||||||||||
list(js, css) | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use yet the markdown syntax by default in this package. So you need to use usual Rd syntax or set
@md
in this specific doc.If we do the latter, we may take the opportunity to convert this whole help page.
The former is easier for you as this is one link.