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

172 lines
4.7KB

  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/write_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. )
  96. # ---- Duotone ----
  97. setup_theme_function(
  98. "duo",
  99. template_duo,
  100. "#' @template duo",
  101. "#' @family Duotone themes",
  102. "#' @export",
  103. body = c(
  104. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  105. " eval(parse(text = call_write_xaringan_theme()))"
  106. ),
  107. file = here::here("R/duo.R")
  108. )
  109. # ---- Duotone Accent ----
  110. setup_theme_function(
  111. "duo_accent",
  112. template_duo_accent,
  113. "#' @template duo_accent",
  114. "#' @family Duotone themes",
  115. "#' @export",
  116. body = c(
  117. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  118. " eval(parse(text = call_write_xaringan_theme()))"
  119. ),
  120. file = here::here("R/duo_accent.R")
  121. )
  122. # ---- Duotone Accent Inverse ----
  123. setup_theme_function(
  124. "duo_accent_inverse",
  125. template_duo_accent_inverse,
  126. "#' @template duo_accent_inverse",
  127. "#' @family Duotone themes",
  128. "#' @export",
  129. body = c(
  130. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  131. " eval(parse(text = call_write_xaringan_theme()))"
  132. ),
  133. file = here::here("R/duo_accent_inverse.R")
  134. )
  135. # ---- Solarized Light ----
  136. setup_theme_function(
  137. "solarized_light",
  138. template_solarized_light,
  139. "#' @template solarized_light",
  140. "#' @family Solarized themes",
  141. "#' @export",
  142. body = c(
  143. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  144. " eval(parse(text = call_write_xaringan_theme()))"
  145. ),
  146. file = here::here("R/solarized_light.R")
  147. )
  148. # ---- Solarized Dark ----
  149. setup_theme_function(
  150. "solarized_dark",
  151. template_solarized_dark,
  152. "#' @template solarized_dark",
  153. "#' @family Solarized themes",
  154. "#' @export",
  155. body = c(
  156. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  157. " eval(parse(text = call_write_xaringan_theme()))"
  158. ),
  159. file = here::here("R/solarized_dark.R")
  160. )