style_* returns name of file invisiblytags/v0.3.0
| @@ -31,9 +31,10 @@ | |||
| #' @inheritParams style_xaringan | |||
| #' @export | |||
| 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( | |||
| "\n\n/* Extra CSS */", | |||
| list2css(css), | |||
| x, | |||
| file = outfile, | |||
| append = TRUE, | |||
| sep = "\n" | |||
| @@ -255,7 +255,12 @@ style_xaringan <- function( | |||
| template <- readLines(tf, warn = FALSE) | |||
| template <- paste(template, collapse = "\n") | |||
| 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) | |||
| if (!is.null(extra_css)) style_extra_css(extra_css, outfile) | |||
| outfile | |||
| invisible(outfile) | |||
| } | |||
| @@ -119,6 +119,11 @@ tf <- system.file("resources", "template.css", package = "xaringanthemer") | |||
| template <- readLines(tf, warn = FALSE) | |||
| template <- paste(template, collapse = "\n") | |||
| 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) | |||
| if (!is.null(extra_css)) style_extra_css(extra_css, outfile) | |||
| outfile | |||
| invisible(outfile) | |||
| @@ -2,7 +2,6 @@ with_clean_session <- function(.f, args = list()) { | |||
| empty_wd <- tempfile() | |||
| dir.create(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) | |||
| } | |||
| @@ -72,3 +72,20 @@ test_that("default fonts are correctly identified as google font", { | |||
| 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) | |||
| }) | |||
| 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))) | |||
| }) | |||