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

167 lines
4.1KB

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