😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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