You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 satır
1.7KB

  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. cp_to_rstudio <- function(file) {
  19. # cliapp::cli_alert("{arg \"{get_theme_name(file)}\"}")
  20. fs::file_copy(
  21. file,
  22. fs::path_home_r(".R", "rstudio", "themes", fs::path_file(file)),
  23. overwrite = TRUE
  24. )
  25. }
  26. make_base16_theme <- function(palette_file) {
  27. base16_palette <- fs::path_file(palette_file)
  28. base16_info <- get_base16_theme_info(palette_file)
  29. base16_attribution <- base16_info$attribution
  30. base16_rstudio_style <- base16_info$rstudio_style
  31. base16_name <- base16_info$name
  32. base16_theme <- whisker::whisker.render(
  33. readLines(here::here("src/base16/base16_template.scss"), warn = FALSE)
  34. )
  35. base16_theme_file <- sub("^_", "", base16_palette)
  36. # cliapp::cli_alert("Creating src/{arg {base16_theme_file}}")
  37. writeLines(base16_theme, fs::path(here::here("src", base16_theme_file)))
  38. }
  39. get_base16_theme_info <- function(palette_file) {
  40. info <- list()
  41. base16_meta <- readLines(palette_file, n = 2)
  42. info$attribution <- base16_meta[1]
  43. info$rstudio_style <- base16_meta[2]
  44. if (base16_meta[2] == "") {
  45. info$rstudio_style <- "/* rs-theme-is-dark: TRUE */"
  46. }
  47. info$name <- stringr::str_match(info$attribution, "\\s*([\\w ]+) by")[1, 2]
  48. info
  49. }