😎 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.

192 Zeilen
5.3KB

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