Procházet zdrojové kódy

Move make functions to R/

one
Garrick Aden-Buie před 7 roky
rodič
revize
2c59b77b4c
2 změnil soubory, kde provedl 29 přidání a 27 odebrání
  1. +28
    -0
      R/make_functions.R
  2. +1
    -27
      make.R

+ 28
- 0
R/make_functions.R Zobrazit soubor

@@ -0,0 +1,28 @@
render_sass <- function(file, output = NULL, outdir = "dist") {
if (is.null(output)) {
output <- fs::path_file(file)
fs::path_ext(output) <- "rstheme"
}
output <- fs::path(outdir, output)
cliapp::cli_alert_success("{path {fs::path_rel(file, getwd())}}")
sass::sass(sass::sass_file(paste(file)), output = output)
}


get_theme_name <- function(file) {
x <- readLines(file, warn = FALSE)
x <- grep("rs-theme-name", x, value = TRUE)
if (!length(x)) return("")
x <- sub("^\\s*/\\*\\s*rs-theme-name:\\s", "", x)
x <- sub("\\s*\\*/\\s*$", "", x)
x
}

cp_to_rstudio <- function(file) {
cliapp::cli_alert("{arg \"{get_theme_name(file)}\"}")
fs::file_copy(
file,
fs::path_home_r(".R", "rstudio", "themes", fs::path_file(file)),
overwrite = TRUE
)
}

+ 1
- 27
make.R Zobrazit soubor

@@ -4,15 +4,7 @@ library(fs)
library(purrr)
library(cliapp)

render_sass <- function(file, output = NULL, outdir = "dist") {
if (is.null(output)) {
output <- path_file(file)
path_ext(output) <- "rstheme"
}
output <- path(outdir, output)
cli_alert_success("{path {path_rel(file, getwd())}}")
sass(sass_file(paste(file)), output = output)
}
source("R/make_functions.R")

dir_create("dist")

@@ -20,24 +12,6 @@ cli_alert_info("Compiling themes...")
dir_ls("src", regexp = "^[^_].+\\.scss") %>%
walk(render_sass)

get_theme_name <- function(file) {
x <- readLines(file, warn = FALSE)
x <- grep("rs-theme-name", x, value = TRUE)
if (!length(x)) return("")
x <- sub("^\\s*/\\*\\s*rs-theme-name:\\s", "", x)
x <- sub("\\s*\\*/\\s*$", "", x)
x
}

cp_to_rstudio <- function(file) {
cli_alert("{arg \"{get_theme_name(file)}\"}")
file_copy(
file,
path_home_r(".R", "rstudio", "themes", path_file(file)),
overwrite = TRUE
)
}

cli_alert_info('Installing themes to {path {path_home_r(".R", "rstudio", "themes")}}')
dir_ls("dist", regexp = "\\.rstheme") %>%
walk(cp_to_rstudio)

Načítá se…
Zrušit
Uložit