😎 Give your xaringan slides some style
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

187 líneas
4.6KB

  1. source(here::here("R/utils_theme-gen.R"))
  2. load(here::here("R/sysdata.rda"))
  3. # R/theme_settings.R contains element_description() and plural_elements()
  4. setup_theme_function <- function(
  5. f_name = "style_xaringan",
  6. template = template_variables,
  7. ...,
  8. file = "",
  9. body = " eval(parse(text = call_style_xaringan()))"
  10. ) {
  11. if (file == "clip" && !requireNamespace("clipr", quietly = TRUE)) file <- ""
  12. body <- c(
  13. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  14. body
  15. )
  16. tv <- template
  17. null_default <- purrr::map_lgl(tv$default, is.null)
  18. tv[null_default, "default"] <- "{NULL}"
  19. x <- c(
  20. "# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand\n",
  21. as.character(
  22. glue::glue_data(
  23. tv,
  24. "#' @param {variable} {description}. ",
  25. "Defaults to {gsub('[{{}}]', '`', default)}. ",
  26. "{element_description(element)}"
  27. )
  28. ),
  29. "#' @template theme_params",
  30. ...,
  31. glue::glue("{f_name} <- function("),
  32. as.character(
  33. glue::glue_data(
  34. tv,
  35. " {variable} = {ifelse(!grepl('^[{].+[}]$', default), paste0('\"', default, '\"'), gsub('[{}]', '', default))},"
  36. )
  37. ),
  38. " colors = NULL,",
  39. " extra_css = NULL,",
  40. " extra_fonts = NULL,",
  41. " outfile = \"xaringan-themer.css\"",
  42. ") {"
  43. )
  44. if (!is.null(body)) x <- c(x, body, "}")
  45. if (file == "clip") {
  46. clipr::write_clip(x)
  47. message("Wrote ", f_name, " function signature to clipboard.")
  48. } else {
  49. cat(reflow_roxygen(x), sep = "\n", file = file)
  50. message("Wrote ", f_name, " to ", file)
  51. }
  52. invisible()
  53. }
  54. reflow_roxygen <- function(x) {
  55. is_roxy_tag <- grepl("^#' @", x)
  56. roxy_tags <- x[is_roxy_tag]
  57. roxy_tags <- sub("^#' ", "", roxy_tags)
  58. roxy_tags <- purrr::map_chr(
  59. roxy_tags,
  60. ~ paste(
  61. "#'", strwrap(
  62. pack_inline_code(.x),
  63. width = 77,
  64. exdent = 2
  65. ), collapse = "\n")
  66. )
  67. roxy_tags <- gsub("\u00A0", " ", roxy_tags)
  68. x[is_roxy_tag] <- roxy_tags
  69. x
  70. }
  71. pack_inline_code <- function(x) {
  72. stopifnot(length(x) == 1, is.character(x))
  73. x <- strsplit(x, "")[[1]]
  74. inline_code <- FALSE
  75. for (i in seq_along(x)) {
  76. if (identical(x[i], "`")) {
  77. inline_code <- !inline_code
  78. } else if (inline_code && identical(x[i], " ")) {
  79. x[i] <- "\u00A0"
  80. }
  81. }
  82. paste(x, collapse = "")
  83. }
  84. # ---- Write Xaringan Theme Function ----
  85. setup_theme_function(
  86. "style_xaringan",
  87. template_variables,
  88. "#' @template style_xaringan",
  89. "#' @export",
  90. body = paste0(" ", readLines(here::here("inst/scripts/style_xaringan_body.R"))),
  91. file = here::here("R/style_xaringan.R")
  92. )
  93. # ---- Monotone Light ----
  94. setup_theme_function(
  95. "style_mono_light",
  96. template_mono_light,
  97. "#' @template style_mono_light",
  98. "#' @family Monotone themes",
  99. "#' @export",
  100. file = here::here("R/style_mono_light.R")
  101. )
  102. # ---- Monotone Dark ----
  103. setup_theme_function(
  104. "style_mono_dark",
  105. template_mono_dark,
  106. "#' @template style_mono_dark",
  107. "#' @family Monotone themes",
  108. "#' @export",
  109. file = here::here("R/style_mono_dark.R")
  110. )
  111. # ---- Monotone Accent ----
  112. setup_theme_function(
  113. "style_mono_accent",
  114. template_mono_accent,
  115. "#' @template style_mono_accent",
  116. "#' @family Monotone themes",
  117. "#' @export",
  118. file = here::here("R/style_mono_accent.R")
  119. )
  120. # ---- Monotone Accent Inverse ----
  121. setup_theme_function(
  122. "style_mono_accent_inverse",
  123. template_mono_accent_inverse,
  124. "#' @template style_mono_accent_inverse",
  125. "#' @family Monotone themes",
  126. "#' @export",
  127. file = here::here("R/style_mono_accent_inverse.R")
  128. )
  129. # ---- Duotone ----
  130. setup_theme_function(
  131. "style_duo",
  132. template_duo,
  133. "#' @template style_duo",
  134. "#' @family Duotone themes",
  135. "#' @export",
  136. file = here::here("R/style_duo.R")
  137. )
  138. # ---- Duotone Accent ----
  139. setup_theme_function(
  140. "style_duo_accent",
  141. template_duo_accent,
  142. "#' @template style_duo_accent",
  143. "#' @family Duotone themes",
  144. "#' @export",
  145. file = here::here("R/style_duo_accent.R")
  146. )
  147. # ---- Duotone Accent Inverse ----
  148. setup_theme_function(
  149. "style_duo_accent_inverse",
  150. template_duo_accent_inverse,
  151. "#' @template style_duo_accent_inverse",
  152. "#' @family Duotone themes",
  153. "#' @export",
  154. file = here::here("R/style_duo_accent_inverse.R")
  155. )
  156. # ---- Solarized Light ----
  157. setup_theme_function(
  158. "style_solarized_light",
  159. template_solarized_light,
  160. "#' @template style_solarized_light",
  161. "#' @family Solarized themes",
  162. "#' @export",
  163. file = here::here("R/style_solarized_light.R")
  164. )
  165. # ---- Solarized Dark ----
  166. setup_theme_function(
  167. "style_solarized_dark",
  168. template_solarized_dark,
  169. "#' @template style_solarized_dark",
  170. "#' @family Solarized themes",
  171. "#' @export",
  172. file = here::here("R/style_solarized_dark.R")
  173. )