Преглед изворни кода

output = NULL returns css and doesn't write file

style_* returns name of file invisibly
tags/v0.3.0
Garrick Aden-Buie пре 6 година
родитељ
комит
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 Прегледај датотеку

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

+ 7
- 2
R/style_xaringan.R Прегледај датотеку

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

+ 7
- 2
inst/scripts/style_xaringan_body.R Прегледај датотеку

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)

+ 1
- 2
tests/testthat/helper-session.R Прегледај датотеку

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

+ 17
- 0
tests/testthat/test-themes.R Прегледај датотеку

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

Loading…
Откажи
Сачувај