Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

78 lines
2.4KB

  1. render_sass <- function(file, output = NULL, outdir = "dist") {
  2. if (is.null(output)) {
  3. output <- fs::path_file(file)
  4. fs::path_ext(output) <- "rstheme"
  5. }
  6. output <- fs::path(outdir, output)
  7. # cliapp::cli_alert_success("{path {fs::path_rel(file, getwd())}}")
  8. sass::sass(sass::sass_file(paste(file)), output = output)
  9. }
  10. get_theme_name <- function(file) {
  11. x <- readLines(file, warn = FALSE)
  12. x <- grep("rs-theme-name", x, value = TRUE)
  13. if (!length(x)) return("")
  14. x <- sub("^\\s*/\\*\\s*rs-theme-name:\\s", "", x)
  15. x <- sub("\\s*\\*/\\s*$", "", x)
  16. x
  17. }
  18. list_sassy_themes <- function(style = c("all", "light", "dark")) {
  19. if (!requireNamespace("rstudioapi", quietly = TRUE)) {
  20. stop("The {rstudioapi} package is required")
  21. }
  22. if (!rstudioapi::hasFun("getThemes")) {
  23. stop("Please upgrade RStudio to version 1.2+")
  24. }
  25. themes <- rstudioapi::getThemes()
  26. themes <- switch(
  27. match.arg(style),
  28. light = purrr::discard(themes, "isDark"),
  29. dark = purrr::keep(themes, "isDark"),
  30. themes
  31. )
  32. themes <- purrr::map_chr(themes, "name")
  33. themes <- themes[grepl("Sassy", themes)]
  34. unname(themes)
  35. }
  36. cp_to_rstudio <- function(file) {
  37. # cliapp::cli_alert("{arg \"{get_theme_name(file)}\"}")
  38. fs::file_copy(
  39. file,
  40. fs::path_home_r(".R", "rstudio", "themes", fs::path_file(file)),
  41. overwrite = TRUE
  42. )
  43. }
  44. base16_make_theme <- function(palette_file) {
  45. base16_palette <- fs::path_file(palette_file)
  46. base16_info <- base16_get_theme_info(palette_file)
  47. base16_attribution <- base16_info$attribution
  48. base16_name <- base16_info$name
  49. if (base16_info$isDark) base16_rstudio_style <- base16_info$rstudio_style
  50. base16_theme <- whisker::whisker.render(
  51. readLines(here::here("src/base16/base16_template.scss"), warn = FALSE)
  52. )
  53. base16_theme_file <- sub("^_", "", base16_palette)
  54. # cliapp::cli_alert("Creating src/{arg {base16_theme_file}}")
  55. writeLines(base16_theme, fs::path(here::here("src", base16_theme_file)))
  56. }
  57. base16_get_theme_info <- function(palette_file) {
  58. info <- list()
  59. base16_meta <- readLines(palette_file, n = 2)
  60. info$attribution <- base16_meta[1]
  61. info$rstudio_style <- base16_meta[2]
  62. info$isDark <- FALSE
  63. if (base16_meta[2] == "") {
  64. info$isDark <- TRUE
  65. info$rstudio_style <- "/* rs-theme-is-dark: TRUE */"
  66. }
  67. rgx_name <- "/\\*\\s*([[:alpha:][:punct:] ]+) by"
  68. info$name <- stringr::str_match(info$attribution, rgx_name)[1, 2]
  69. info
  70. }