😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

161 lines
4.3KB

  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. as.character(
  20. glue::glue_data(
  21. tv,
  22. "#' @param {variable} {description}. ",
  23. "Defaults to {gsub('[{{}}]', '`', default)}. ",
  24. "{element_description(element)}"
  25. )
  26. ),
  27. "#' @param colors A named vector of custom colors. The names of the colors",
  28. "#' become CSS variables and classes that can be used within your slides.",
  29. "#' For example, `colors = c(blue = \"#bad4ed\")` adds a CSS variable",
  30. "#' `--blue`, a `.blue` CSS class that applies the color to the text or",
  31. "#' foreground color, and a `.bg-blue` CSS class that applies the color",
  32. "#' to the background.",
  33. "#' @template extra_css",
  34. "#' @param outfile Customized xaringan CSS output file name, default is \"xaringan-themer.css\"",
  35. "#' @family themes",
  36. ...,
  37. glue::glue("{f_name} <- function("),
  38. as.character(
  39. glue::glue_data(
  40. tv,
  41. " {variable} = {ifelse(!grepl('^[{].+[}]$', default), paste0('\"', default, '\"'), gsub('[{}]', '', default))},"
  42. )
  43. ),
  44. " colors = NULL,",
  45. " extra_css = NULL,",
  46. " extra_fonts = NULL,",
  47. " outfile = \"xaringan-themer.css\"",
  48. ") {"
  49. )
  50. if (!is.null(body)) x <- c(x, body, "}")
  51. if (file == "clip") {
  52. clipr::write_clip(x)
  53. message("Wrote ", f_name, " function signature to clipboard.")
  54. } else {
  55. cat(x, sep = "\n", file = file)
  56. message("Wrote ", f_name, " to ", file)
  57. }
  58. invisible()
  59. }
  60. # ---- Write Xaringan Theme Function ----
  61. setup_theme_function(
  62. "style_xaringan",
  63. template_variables,
  64. "#' @template style_xaringan",
  65. "#' @export",
  66. body = paste0(" ", readLines(here::here("inst/scripts/style_xaringan_body.R"))),
  67. file = here::here("R/style_xaringan.R")
  68. )
  69. # ---- Monotone Light ----
  70. setup_theme_function(
  71. "style_mono_light",
  72. template_mono_light,
  73. "#' @template style_mono_light",
  74. "#' @family Monotone themes",
  75. "#' @export",
  76. file = here::here("R/style_mono_light.R")
  77. )
  78. # ---- Monotone Dark ----
  79. setup_theme_function(
  80. "style_mono_dark",
  81. template_mono_dark,
  82. "#' @template style_mono_dark",
  83. "#' @family Monotone themes",
  84. "#' @export",
  85. file = here::here("R/style_mono_dark.R")
  86. )
  87. # ---- Monotone Accent ----
  88. setup_theme_function(
  89. "style_mono_accent",
  90. template_mono_accent,
  91. "#' @template style_mono_accent",
  92. "#' @family Monotone themes",
  93. "#' @export",
  94. file = here::here("R/style_mono_accent.R")
  95. )
  96. # ---- Monotone Accent Inverse ----
  97. setup_theme_function(
  98. "style_mono_accent_inverse",
  99. template_mono_accent_inverse,
  100. "#' @template style_mono_accent_inverse",
  101. "#' @family Monotone themes",
  102. "#' @export",
  103. file = here::here("R/style_mono_accent_inverse.R")
  104. )
  105. # ---- Duotone ----
  106. setup_theme_function(
  107. "style_duo",
  108. template_duo,
  109. "#' @template style_duo",
  110. "#' @family Duotone themes",
  111. "#' @export",
  112. file = here::here("R/style_duo.R")
  113. )
  114. # ---- Duotone Accent ----
  115. setup_theme_function(
  116. "style_duo_accent",
  117. template_duo_accent,
  118. "#' @template style_duo_accent",
  119. "#' @family Duotone themes",
  120. "#' @export",
  121. file = here::here("R/style_duo_accent.R")
  122. )
  123. # ---- Duotone Accent Inverse ----
  124. setup_theme_function(
  125. "style_duo_accent_inverse",
  126. template_duo_accent_inverse,
  127. "#' @template style_duo_accent_inverse",
  128. "#' @family Duotone themes",
  129. "#' @export",
  130. file = here::here("R/style_duo_accent_inverse.R")
  131. )
  132. # ---- Solarized Light ----
  133. setup_theme_function(
  134. "style_solarized_light",
  135. template_solarized_light,
  136. "#' @template style_solarized_light",
  137. "#' @family Solarized themes",
  138. "#' @export",
  139. file = here::here("R/style_solarized_light.R")
  140. )
  141. # ---- Solarized Dark ----
  142. setup_theme_function(
  143. "style_solarized_dark",
  144. template_solarized_dark,
  145. "#' @template style_solarized_dark",
  146. "#' @family Solarized themes",
  147. "#' @export",
  148. file = here::here("R/style_solarized_dark.R")
  149. )