Skip to content

Commit

Permalink
Make ioslides_presentation() more themable via {bslib} and {sass}
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jan 20, 2021
1 parent 95eed06 commit e2a9f41
Show file tree
Hide file tree
Showing 2 changed files with 1,601 additions and 14 deletions.
70 changes: 56 additions & 14 deletions R/ioslides_presentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -291,7 +295,7 @@ ioslides_presentation <- function(number_sections = FALSE,

# html dependency for ioslides
extra_dependencies <- append(extra_dependencies,
list(html_dependency_ioslides()))
html_dependency_ioslides(theme))

# analytics
if (!is.null(analytics))
Expand Down Expand Up @@ -453,14 +457,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) {
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",
Expand All @@ -470,10 +476,46 @@ 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")
)
)

if (is.null(theme)) {
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))
}

theme <- as_bs_theme(theme)
if (!is_bs_theme(theme)) {
stop("`theme` must be a `bslib::bs_theme()` object or a list of arguments to it")
}
if ("3" %in% theme_version(theme)) {
stop("`ioslides_presentation()` is not compatible with Bootstrap 3 (use version = 4 or higher)")
}
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)
}
Loading

0 comments on commit e2a9f41

Please sign in to comment.