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

list2css() handles duplicated selectors and property names

tags/v0.3.0
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
8025d1ea61
2 измененных файлов: 17 добавлений и 4 удалений
  1. +5
    -4
      R/style_extra_css.R
  2. +12
    -0
      tests/testthat/test-style_extra_css.R

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

@@ -100,19 +100,20 @@ list2css <- function(css) {
stop(msg, call. = FALSE)
}

purrr::map_chr(names(css), function(el) {
x <- purrr::imap_chr(css, function(rules, selector) {
paste(
sep = "\n",
el %.% " {",
selector %.% " {",
paste(
purrr::map_chr(names(css[[el]]), function(prop) {
" " %.% prop %.% ": " %.% css[[el]][[prop]] %.% ";"
purrr::imap_chr(rules, function(value, prop) {
" " %.% prop %.% ": " %.% value %.% ";"
}),
collapse = "\n"
),
"}"
)
})
unname(x)
}

list2fonts <- function(fonts) {

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

@@ -166,6 +166,18 @@ describe("list2css()", {
"elements.+must be named.+body, thing.+have"
)
})

it("is okay for multiple entries with the same name", {
expect_equal(
list2css(list("a" = list(color = "red"), a = list(color = "blue"))),
c("a {\n color: red;\n}", "a {\n color: blue;\n}")
)

expect_equal(
list2css(list("a" = list(color = "red", color = "blue"))),
c("a {\n color: red;\n color: blue;\n}")
)
})
})



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