瀏覽代碼

Warn if colors used by theme_xaringan() are not in hex format

tags/v0.3.0
Garrick Aden-Buie 6 年之前
父節點
當前提交
34bf66dbca
共有 3 個文件被更改,包括 62 次插入0 次删除
  1. +25
    -0
      R/style_xaringan.R
  2. +25
    -0
      inst/scripts/style_xaringan_body.R
  3. +12
    -0
      tests/testthat/test-themes.R

+ 25
- 0
R/style_xaringan.R 查看文件

) )
} }
# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list(
background_color = background_color,
text_color = text_color,
header_color = header_color,
text_bold_color = text_bold_color,
inverse_background_color = inverse_background_color,
inverse_text_color = inverse_text_color,
inverse_header_color = inverse_header_color
)
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE,
call. = FALSE
)
}
# Use font_..._google args to overwrite font args # Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) { for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var)) gf <- eval(parse(text = var))

+ 25
- 0
inst/scripts/style_xaringan_body.R 查看文件

) )
} }


# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list(
background_color = background_color,
text_color = text_color,
header_color = header_color,
text_bold_color = text_bold_color,
inverse_background_color = inverse_background_color,
inverse_text_color = inverse_text_color,
inverse_header_color = inverse_header_color
)
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)

if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE,
call. = FALSE
)
}

# Use font_..._google args to overwrite font args # Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) { for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var)) gf <- eval(parse(text = var))

+ 12
- 0
tests/testthat/test-themes.R 查看文件

expect_type(xt, "character") expect_type(xt, "character")
expect_true(any(grepl("generated by xaringanthemer", xt))) expect_true(any(grepl("generated by xaringanthemer", xt)))
}) })


test_that("style_xaringan() warns about non-hex colors used by theme_xaringan()", {
expect_error(
with_clean_session(function() {
options(warn = 2)
xaringanthemer::style_xaringan(text_color = "rgb(100, 100, 100)", background_color = "white", outfile = NULL)
}),
regexp = "Colors.+used by.+theme_xaringan",
class = "callr_status_error"
)
})

Loading…
取消
儲存