ソースを参照

change regex pattern to match valid css class names (#69)

* The style functions are now more permissive about color names in the `color` argument. Color names should be valid CSS classes that can also be used as CSS variable names, but the `style_` function only stops with an error if the color name contains spaces. (@jdlom #69)
tags/v0.4.1
jdlom 4年前
コミット
c606bdf7c9
コミッターのメールアドレスに関連付けられたアカウントが存在しません
2個のファイルの変更22行の追加3行の削除
  1. +7
    -2
      R/color.R
  2. +15
    -1
      tests/testthat/test-color.R

+ 7
- 2
R/color.R ファイルの表示

call. = FALSE) call. = FALSE)
} }


if (any(grepl("[^[:alpha:]_-]", names(colors)))) {
stop("Color names in `colors` must be valid CSS classes", call. = FALSE)
maybe_bad_css <- unique(grep("^[_-]|[ .>~*:|+}/]", names(colors), value = TRUE))
if (length(maybe_bad_css) > 0) {
warning(
"Color names in `colors` should be valid CSS classes: ",
paste0("'", maybe_bad_css, "'", collapse = ", "),
call. = FALSE
)
} }


whisker::iteratelist(colors, "color_name") whisker::iteratelist(colors, "color_name")

+ 15
- 1
tests/testthat/test-color.R ファイルの表示



it("requires valid CSS names", { it("requires valid CSS names", {
expect_error(prepare_colors(c("light blue" = "#88f"))) expect_error(prepare_colors(c("light blue" = "#88f")))
expect_error(prepare_colors(c("light/blue" = "#88f")))
expect_warning(prepare_colors(c("light/blue" = "#88f")), "light/blue")
expect_warning(prepare_colors(c("-lightblue" = "#88f")), "-lightblue")
expect_warning(prepare_colors(c("_lightblue" = "#88f")), "_lightblue")
colors <- c("light_blue" = "#88f", "light-blue" = "#88f")
expect_silent(
expect_equal(
prepare_colors(colors),
list(
list(color_name = "light_blue", value = "#88f"),
list(color_name = "light-blue", value = "#88f")
)
)
)
}) })



it("returns list with color_name and value for each color", { it("returns list with color_name and value for each color", {
colors <- c('test' = "#4ed4ed") colors <- c('test' = "#4ed4ed")
prepared <- prepare_colors(colors) prepared <- prepare_colors(colors)

読み込み中…
キャンセル
保存