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

153 lines
3.9KB

  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 = c(
  9. " # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
  10. " eval(parse(text = call_style_xaringan()))"
  11. )
  12. ) {
  13. if (file == "clip" && !requireNamespace("clipr", quietly = TRUE)) file <- ""
  14. tv <- template
  15. null_default <- purrr::map_lgl(tv$default, is.null)
  16. tv[null_default, "default"] <- "{NULL}"
  17. x <- c(
  18. as.character(
  19. glue::glue_data(
  20. tv,
  21. "#' @param {variable} {description}. ",
  22. "Defaults to {gsub('[{{}}]', '`', default)}. ",
  23. "{element_description(element)}"
  24. )
  25. ),
  26. "#' @template extra_css",
  27. "#' @param outfile Customized xaringan CSS output file name, default is \"xaringan-themer.css\"",
  28. "#' @family themes",
  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. " extra_css = NULL,",
  38. " extra_fonts = NULL,",
  39. " outfile = \"xaringan-themer.css\"",
  40. ") {"
  41. )
  42. if (!is.null(body)) x <- c(x, body, "}")
  43. if (file == "clip") {
  44. clipr::write_clip(x)
  45. message("Wrote ", f_name, " function signature to clipboard.")
  46. } else {
  47. cat(x, sep = "\n", file = file)
  48. message("Wrote ", f_name, " to ", file)
  49. }
  50. invisible()
  51. }
  52. # ---- Write Xaringan Theme Function ----
  53. setup_theme_function(
  54. "style_xaringan",
  55. template_variables,
  56. "#' @template style_xaringan",
  57. "#' @export",
  58. body = paste0(" ", readLines(here::here("inst/scripts/style_xaringan_body.R"))),
  59. file = here::here("R/style_xaringan.R")
  60. )
  61. # ---- Monotone Light ----
  62. setup_theme_function(
  63. "style_mono_light",
  64. template_mono_light,
  65. "#' @template style_mono_light",
  66. "#' @family Monotone themes",
  67. "#' @export",
  68. file = here::here("R/style_mono_light.R")
  69. )
  70. # ---- Monotone Dark ----
  71. setup_theme_function(
  72. "style_mono_dark",
  73. template_mono_dark,
  74. "#' @template style_mono_dark",
  75. "#' @family Monotone themes",
  76. "#' @export",
  77. file = here::here("R/style_mono_dark.R")
  78. )
  79. # ---- Monotone Accent ----
  80. setup_theme_function(
  81. "style_mono_accent",
  82. template_mono_accent,
  83. "#' @template style_mono_accent",
  84. "#' @family Monotone themes",
  85. "#' @export",
  86. file = here::here("R/style_mono_accent.R")
  87. )
  88. # ---- Monotone Accent Inverse ----
  89. setup_theme_function(
  90. "style_mono_accent_inverse",
  91. template_mono_accent_inverse,
  92. "#' @template style_mono_accent_inverse",
  93. "#' @family Monotone themes",
  94. "#' @export",
  95. file = here::here("R/style_mono_accent_inverse.R")
  96. )
  97. # ---- Duotone ----
  98. setup_theme_function(
  99. "style_duo",
  100. template_duo,
  101. "#' @template style_duo",
  102. "#' @family Duotone themes",
  103. "#' @export",
  104. file = here::here("R/style_duo.R")
  105. )
  106. # ---- Duotone Accent ----
  107. setup_theme_function(
  108. "style_duo_accent",
  109. template_duo_accent,
  110. "#' @template style_duo_accent",
  111. "#' @family Duotone themes",
  112. "#' @export",
  113. file = here::here("R/style_duo_accent.R")
  114. )
  115. # ---- Duotone Accent Inverse ----
  116. setup_theme_function(
  117. "style_duo_accent_inverse",
  118. template_duo_accent_inverse,
  119. "#' @template style_duo_accent_inverse",
  120. "#' @family Duotone themes",
  121. "#' @export",
  122. file = here::here("R/style_duo_accent_inverse.R")
  123. )
  124. # ---- Solarized Light ----
  125. setup_theme_function(
  126. "style_solarized_light",
  127. template_solarized_light,
  128. "#' @template style_solarized_light",
  129. "#' @family Solarized themes",
  130. "#' @export",
  131. file = here::here("R/style_solarized_light.R")
  132. )
  133. # ---- Solarized Dark ----
  134. setup_theme_function(
  135. "style_solarized_dark",
  136. template_solarized_dark,
  137. "#' @template style_solarized_dark",
  138. "#' @family Solarized themes",
  139. "#' @export",
  140. file = here::here("R/style_solarized_dark.R")
  141. )