😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

36 lines
1.2KB

  1. #' @keywords internal
  2. setup_theme_function <- function(
  3. f_name = "write_xaringan_theme",
  4. template = template_variables,
  5. ...,
  6. to_clipboard = TRUE,
  7. body = NULL
  8. ) {
  9. `%,%` <- function(x, y) c(x, y)
  10. tv <- template
  11. null_default <- purrr::map_lgl(tv$default, is.null)
  12. tv[null_default, 'default'] <- "{NULL}"
  13. x <-
  14. as.character(
  15. glue::glue_data(
  16. tv, "#' @param {variable} {description}, defaults to {stringr::str_replace_all(default, '[{{}}]', '`')}")) %,%
  17. "#' @param outfile Customized xaringan CSS output file name" %,%
  18. c(...) %,%
  19. glue::glue("{f_name} <- function(") %,%
  20. as.character(glue::glue_data(tv,
  21. " {variable} = {ifelse(!stringr::str_detect(default, '^[{].+[}]$'), paste0('\"', default, '\"'), stringr::str_replace_all(default, '[{}]', ''))},")) %,%
  22. " outfile = \"xaringan-themed.css\"" %,%
  23. ") {"
  24. if (!is.null(body)) x <- c(x, body, "}")
  25. if (to_clipboard) message("Wrote function signature to clipboard.")
  26. cat(x, sep = "\n",
  27. file = if(to_clipboard) pipe("pbcopy", "w") else "")
  28. }
  29. #' @keywords internal
  30. call_write_xaringan_theme <- function() {
  31. paste0("write_xaringan_theme(",
  32. paste(template_variables$variable, collapse = ", "),
  33. ")")
  34. }