|
|
|
|
|
|
|
|
read_css_vars <- function(file = NULL) { |
|
|
read_css_vars <- function(file = NULL) { |
|
|
if (is.null(file)) { |
|
|
if (is.null(file)) { |
|
|
css_candidates <- find_xaringan_themer_css() |
|
|
css_candidates <- find_xaringan_themer_css() |
|
|
if (!length(css_candidates)) { |
|
|
|
|
|
stop("Unable to locate a xaringanthemer css file.") |
|
|
|
|
|
} else if (length(css_candidates) == 1) { |
|
|
|
|
|
file <- css_candidates |
|
|
|
|
|
} else if (length(css_candidates) > 1) { |
|
|
|
|
|
is_xaringan_themer_css <- grepl("xaringan-themer.css", css_candidates, fixed = TRUE) |
|
|
|
|
|
if (any(is_xaringan_themer_css)) { |
|
|
|
|
|
file <- css_candidates[is_xaringan_themer_css][1] |
|
|
|
|
|
} else { |
|
|
|
|
|
file <- css_candidates[1] |
|
|
|
|
|
message(glue::glue("Using xaringanthemer theme in {file}")) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
file <- choose_xaringan_themer_css(css_candidates) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
css_get_root(file) |
|
|
css_get_root(file) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
find_xaringan_themer_css <- function() { |
|
|
find_xaringan_themer_css <- function() { |
|
|
|
|
|
# finds xaringan themer files within or below current working directory |
|
|
|
|
|
# and is only ever intended to be called in that situation |
|
|
css_files <- list.files(pattern = "css$", recursive = TRUE, full.names = TRUE) |
|
|
css_files <- list.files(pattern = "css$", recursive = TRUE, full.names = TRUE) |
|
|
css_files_head <- purrr::map(css_files, readLines, n = 5) |
|
|
css_files_head <- purrr::map(css_files, readLines, n = 5) |
|
|
is_xt <- grepl(pattern = "generated by xaringanthemer", css_files_head, fixed = TRUE) |
|
|
is_xt <- grepl(pattern = "generated by xaringanthemer", css_files_head, fixed = TRUE) |
|
|
|
|
|
|
|
|
css_files[is_xt] |
|
|
css_files[is_xt] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
choose_xaringan_themer_css <- function(css_candidates = character(0)) { |
|
|
|
|
|
if (!length(css_candidates)) { |
|
|
|
|
|
stop("Unable to locate a xaringanthemer css file.", call. = FALSE) |
|
|
|
|
|
} else if (length(css_candidates) == 1) { |
|
|
|
|
|
file <- css_candidates |
|
|
|
|
|
} else if (length(css_candidates) > 1) { |
|
|
|
|
|
is_xaringan_themer_css <- grepl("xaringan-themer.css", css_candidates, fixed = TRUE) |
|
|
|
|
|
if (any(is_xaringan_themer_css)) { |
|
|
|
|
|
file <- css_candidates[is_xaringan_themer_css][1] |
|
|
|
|
|
} else { |
|
|
|
|
|
file <- css_candidates[1] |
|
|
|
|
|
message(glue::glue("Using xaringanthemer theme in {file}")) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
file |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
css_get_root <- function(file) { |
|
|
css_get_root <- function(file) { |
|
|
x <- readLines(file, warn = FALSE) |
|
|
x <- readLines(file, warn = FALSE) |
|
|
x <- paste(x, collapse = "\n") |
|
|
x <- paste(x, collapse = "\n") |