😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

102 lines
2.9KB

  1. source(here::here("R/theme_settings.R"))
  2. setup_theme_function <- function(
  3. f_name = "write_xaringan_theme",
  4. template = template_variables,
  5. ...,
  6. file = "",
  7. body = NULL
  8. ) {
  9. `%,%` <- function(x, y) c(x, y)
  10. if (file == "clip" && !requireNamespace("clipr", quietly = TRUE)) file <- ""
  11. tv <- template
  12. null_default <- purrr::map_lgl(tv$default, is.null)
  13. tv[null_default, 'default'] <- "{NULL}"
  14. x <-
  15. as.character(
  16. glue::glue_data(
  17. tv, "#' @param {variable} {description}, defaults to {stringr::str_replace_all(default, '[{{}}]', '`')}")) %,%
  18. "#' @param outfile Customized xaringan CSS output file name" %,%
  19. c(...) %,%
  20. glue::glue("{f_name} <- function(") %,%
  21. as.character(glue::glue_data(
  22. tv, " {variable} = {ifelse(!stringr::str_detect(default, '^[{].+[}]$'), paste0('\"', default, '\"'), stringr::str_replace_all(default, '[{}]', ''))},")) %,%
  23. " outfile = \"xaringan-themed.css\"" %,%
  24. ") {"
  25. if (!is.null(body)) x <- c(x, body, "}")
  26. if (file == "clip") {
  27. clipr::write_clip(x)
  28. message("Wrote ", f_name, " function signature to clipboard.")
  29. } else {
  30. cat(x, sep = "\n", file = file)
  31. message("Wrote ", f_name, " to ", file)
  32. }
  33. invisible()
  34. }
  35. # ---- Write Xaringan Theme Function ----
  36. setup_theme_function(
  37. "write_xaringan_theme",
  38. template_variables,
  39. "#' @template write_xaringan_theme",
  40. "#' @export",
  41. body = paste0(" ", readLines(here::here("inst/scripts/write_xaringan_theme_body.R"))),
  42. file = here::here("R/theme.R")
  43. )
  44. # ---- Monotone Light ----
  45. setup_theme_function(
  46. "mono_light",
  47. template_mono_light,
  48. "#' @template mono_light",
  49. "#' @family Monotone themes",
  50. "#' @export",
  51. body = c(
  52. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  53. " eval(parse(text = call_write_xaringan_theme()))"
  54. ),
  55. file = here::here("R/mono_light.R")
  56. )
  57. # ---- Monotone Dark ----
  58. setup_theme_function(
  59. "mono_dark",
  60. template_mono_dark,
  61. "#' @template mono_dark",
  62. "#' @family Monotone themes",
  63. "#' @export",
  64. body = c(
  65. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  66. " eval(parse(text = call_write_xaringan_theme()))"
  67. ),
  68. file = here::here("R/mono_dark.R")
  69. )
  70. # ---- Monotone Accent ----
  71. setup_theme_function(
  72. "mono_accent",
  73. template_mono_accent,
  74. "#' @template mono_accent",
  75. "#' @family Monotone themes",
  76. "#' @export",
  77. body = c(
  78. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  79. " eval(parse(text = call_write_xaringan_theme()))"
  80. ),
  81. file = here::here("R/mono_accent.R")
  82. )
  83. # ---- Monotone Accent Inverse ----
  84. setup_theme_function(
  85. "mono_accent_inverse",
  86. template_mono_accent_inverse,
  87. "#' @template mono_accent_inverse",
  88. "#' @family Monotone themes",
  89. "#' @export",
  90. body = c(
  91. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  92. " eval(parse(text = call_write_xaringan_theme()))"
  93. ),
  94. file = here::here("R/mono_accent_inverse.R")
  95. )