style_* returns name of file invisiblytags/v0.3.0
| #' @inheritParams style_xaringan | #' @inheritParams style_xaringan | ||||
| #' @export | #' @export | ||||
| style_extra_css <- function(css, outfile = "xaringan-themer.css", append = TRUE) { | style_extra_css <- function(css, outfile = "xaringan-themer.css", append = TRUE) { | ||||
| x <- paste("\n\n/* Extra CSS */", list2css(css), sep = "\n") | |||||
| if (is.null(outfile)) return(x) | |||||
| cat( | cat( | ||||
| "\n\n/* Extra CSS */", | |||||
| list2css(css), | |||||
| x, | |||||
| file = outfile, | file = outfile, | ||||
| append = TRUE, | append = TRUE, | ||||
| sep = "\n" | sep = "\n" |
| template <- readLines(tf, warn = FALSE) | template <- readLines(tf, warn = FALSE) | ||||
| template <- paste(template, collapse = "\n") | template <- paste(template, collapse = "\n") | ||||
| x <- whisker::whisker.render(template) | x <- whisker::whisker.render(template) | ||||
| if (!is.null(extra_css)) { | |||||
| x <- c(x, style_extra_css(extra_css, outfile = NULL)) | |||||
| } | |||||
| if (is.null(outfile)) { | |||||
| return(x) | |||||
| } | |||||
| writeLines(x, con = outfile) | writeLines(x, con = outfile) | ||||
| if (!is.null(extra_css)) style_extra_css(extra_css, outfile) | |||||
| outfile | |||||
| invisible(outfile) | |||||
| } | } |
| template <- readLines(tf, warn = FALSE) | template <- readLines(tf, warn = FALSE) | ||||
| template <- paste(template, collapse = "\n") | template <- paste(template, collapse = "\n") | ||||
| x <- whisker::whisker.render(template) | x <- whisker::whisker.render(template) | ||||
| if (!is.null(extra_css)) { | |||||
| x <- c(x, style_extra_css(extra_css, outfile = NULL)) | |||||
| } | |||||
| if (is.null(outfile)) { | |||||
| return(x) | |||||
| } | |||||
| writeLines(x, con = outfile) | writeLines(x, con = outfile) | ||||
| if (!is.null(extra_css)) style_extra_css(extra_css, outfile) | |||||
| outfile | |||||
| invisible(outfile) |
| empty_wd <- tempfile() | empty_wd <- tempfile() | ||||
| dir.create(empty_wd) | dir.create(empty_wd) | ||||
| owd <- setwd(empty_wd) | owd <- setwd(empty_wd) | ||||
| message(owd) | |||||
| on.exit({message(owd); setwd(owd); unlink(empty_wd, TRUE)}) | |||||
| on.exit({setwd(owd); unlink(empty_wd, TRUE)}) | |||||
| callr::r_safe(.f, args) | callr::r_safe(.f, args) | ||||
| } | } |
| expect_equal(theme_vars$header_font_family, quote_elements_w_spaces(formals(style_xaringan)$header_font_family)) | expect_equal(theme_vars$header_font_family, quote_elements_w_spaces(formals(style_xaringan)$header_font_family)) | ||||
| expect_true(theme_vars$header_font_is_google) | expect_true(theme_vars$header_font_is_google) | ||||
| }) | }) | ||||
| test_that("NULL output returns CSS as text", { | |||||
| expect_false( | |||||
| with_clean_session(function() { | |||||
| xaringanthemer::style_xaringan(outfile = NULL) | |||||
| file.exists("xaringan-themer.css") | |||||
| }) | |||||
| ) | |||||
| xt <- with_clean_session(function() { | |||||
| xaringanthemer::style_xaringan(outfile = NULL) | |||||
| }) | |||||
| expect_type(xt, "character") | |||||
| expect_true(any(grepl("generated by xaringanthemer", xt))) | |||||
| }) |