😎 Give your xaringan slides some style
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

174 Zeilen
4.8KB

  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. "#' @template extra_css" %,%
  19. "#' @param outfile Customized xaringan CSS output file name, default is \"xaringan-themer.css\"" %,%
  20. c(...) %,%
  21. glue::glue("{f_name} <- function(") %,%
  22. as.character(glue::glue_data(
  23. tv, " {variable} = {ifelse(!stringr::str_detect(default, '^[{].+[}]$'), paste0('\"', default, '\"'), stringr::str_replace_all(default, '[{}]', ''))},")) %,%
  24. " extra_css = NULL," %,%
  25. " outfile = \"xaringan-themer.css\"" %,%
  26. ") {"
  27. if (!is.null(body)) x <- c(x, body, "}")
  28. if (file == "clip") {
  29. clipr::write_clip(x)
  30. message("Wrote ", f_name, " function signature to clipboard.")
  31. } else {
  32. cat(x, sep = "\n", file = file)
  33. message("Wrote ", f_name, " to ", file)
  34. }
  35. invisible()
  36. }
  37. # ---- Write Xaringan Theme Function ----
  38. setup_theme_function(
  39. "write_xaringan_theme",
  40. template_variables,
  41. "#' @template write_xaringan_theme",
  42. "#' @export",
  43. body = paste0(" ", readLines(here::here("inst/scripts/write_xaringan_theme_body.R"))),
  44. file = here::here("R/write_theme.R")
  45. )
  46. # ---- Monotone Light ----
  47. setup_theme_function(
  48. "mono_light",
  49. template_mono_light,
  50. "#' @template mono_light",
  51. "#' @family Monotone themes",
  52. "#' @export",
  53. body = c(
  54. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  55. " eval(parse(text = call_write_xaringan_theme()))"
  56. ),
  57. file = here::here("R/mono_light.R")
  58. )
  59. # ---- Monotone Dark ----
  60. setup_theme_function(
  61. "mono_dark",
  62. template_mono_dark,
  63. "#' @template mono_dark",
  64. "#' @family Monotone themes",
  65. "#' @export",
  66. body = c(
  67. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  68. " eval(parse(text = call_write_xaringan_theme()))"
  69. ),
  70. file = here::here("R/mono_dark.R")
  71. )
  72. # ---- Monotone Accent ----
  73. setup_theme_function(
  74. "mono_accent",
  75. template_mono_accent,
  76. "#' @template mono_accent",
  77. "#' @family Monotone themes",
  78. "#' @export",
  79. body = c(
  80. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  81. " eval(parse(text = call_write_xaringan_theme()))"
  82. ),
  83. file = here::here("R/mono_accent.R")
  84. )
  85. # ---- Monotone Accent Inverse ----
  86. setup_theme_function(
  87. "mono_accent_inverse",
  88. template_mono_accent_inverse,
  89. "#' @template mono_accent_inverse",
  90. "#' @family Monotone themes",
  91. "#' @export",
  92. body = c(
  93. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  94. " eval(parse(text = call_write_xaringan_theme()))"
  95. ),
  96. file = here::here("R/mono_accent_inverse.R")
  97. )
  98. # ---- Duotone ----
  99. setup_theme_function(
  100. "duo",
  101. template_duo,
  102. "#' @template duo",
  103. "#' @family Duotone themes",
  104. "#' @export",
  105. body = c(
  106. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  107. " eval(parse(text = call_write_xaringan_theme()))"
  108. ),
  109. file = here::here("R/duo.R")
  110. )
  111. # ---- Duotone Accent ----
  112. setup_theme_function(
  113. "duo_accent",
  114. template_duo_accent,
  115. "#' @template duo_accent",
  116. "#' @family Duotone themes",
  117. "#' @export",
  118. body = c(
  119. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  120. " eval(parse(text = call_write_xaringan_theme()))"
  121. ),
  122. file = here::here("R/duo_accent.R")
  123. )
  124. # ---- Duotone Accent Inverse ----
  125. setup_theme_function(
  126. "duo_accent_inverse",
  127. template_duo_accent_inverse,
  128. "#' @template duo_accent_inverse",
  129. "#' @family Duotone themes",
  130. "#' @export",
  131. body = c(
  132. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  133. " eval(parse(text = call_write_xaringan_theme()))"
  134. ),
  135. file = here::here("R/duo_accent_inverse.R")
  136. )
  137. # ---- Solarized Light ----
  138. setup_theme_function(
  139. "solarized_light",
  140. template_solarized_light,
  141. "#' @template solarized_light",
  142. "#' @family Solarized themes",
  143. "#' @export",
  144. body = c(
  145. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  146. " eval(parse(text = call_write_xaringan_theme()))"
  147. ),
  148. file = here::here("R/solarized_light.R")
  149. )
  150. # ---- Solarized Dark ----
  151. setup_theme_function(
  152. "solarized_dark",
  153. template_solarized_dark,
  154. "#' @template solarized_dark",
  155. "#' @family Solarized themes",
  156. "#' @export",
  157. body = c(
  158. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  159. " eval(parse(text = call_write_xaringan_theme()))"
  160. ),
  161. file = here::here("R/solarized_dark.R")
  162. )