Просмотр исходного кода

output = NULL returns css and doesn't write file

style_* returns name of file invisibly
tags/v0.3.0
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
978d1ef9e5
5 измененных файлов: 35 добавлений и 8 удалений
  1. +3
    -2
      R/style_extra_css.R
  2. +7
    -2
      R/style_xaringan.R
  3. +7
    -2
      inst/scripts/style_xaringan_body.R
  4. +1
    -2
      tests/testthat/helper-session.R
  5. +17
    -0
      tests/testthat/test-themes.R

+ 3
- 2
R/style_extra_css.R Просмотреть файл

@@ -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"

+ 7
- 2
R/style_xaringan.R Просмотреть файл

@@ -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)
}

+ 7
- 2
inst/scripts/style_xaringan_body.R Просмотреть файл

@@ -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)

+ 1
- 2
tests/testthat/helper-session.R Просмотреть файл

@@ -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)
}

+ 17
- 0
tests/testthat/test-themes.R Просмотреть файл

@@ -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)))
})

Загрузка…
Отмена
Сохранить