😎 Give your xaringan slides some style
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

186 linhas
4.6KB

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