😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

175 lines
4.9KB

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