Sfoglia il codice sorgente

remove unused coolors-related functions

tags/v0.3.0
Garrick Aden-Buie 6 anni fa
parent
commit
d3d61afe3a
2 ha cambiato i file con 0 aggiunte e 37 eliminazioni
  1. +0
    -26
      R/coolors.R
  2. +0
    -11
      tests/testthat/test-coolors2colors.R

+ 0
- 26
R/coolors.R Vedi File

# Xaringan Theme from Coolors URL
# ex: https://coolors.co/fcf7f8-06d6a0-fcb0b3-f93943-7eb2dd
# ex: https://coolors.co/e06c53-ffba49-a3d9ff-d6efff-7e6b8f
# ex: https://coolors.co/ff5e5b-b9d8c2-ffffea-00cecb-ffed66
xaringan_coolors_accent <- function(coolors_url, order = "12345", ...) {
stopifnot(length(coolors_url) == 1)
colors <- coolors2colors(coolors_url)
order <- strplit(order, "")[1]
order <- unlist(purrr::map(order, as.integer))
colors <- colors[order]

colors <- list(
primary = colors[1],
secondary = colors[2]
)

return(colors)
}

coolors2colors <- function(url) {
colors <- sub(".*(([a-f0-9]{6}-?){5}).*", "\\1", url)
colors <- strsplit(colors, "-")
colors <- purrr::map(colors, ~ paste0("#", .))
if (length(colors) == 1) colors[[1]]
else colors
}

+ 0
- 11
tests/testthat/test-coolors2colors.R Vedi File

context("test-coolors2colors.R")

test_that("coolors2colors takes urls and makes #COLORS", {
urls <- c("https://coolors.co/fcf7f8-06d6a0-fcb0b3-f93943-7eb2dd",
"https://coolors.co/e06c53-ffba49-a3d9ff-d6efff-7e6b8f",
"https://coolors.co/ff5e5b-b9d8c2-ffffea-00cecb-ffed66")

expect_equal(coolors2colors(urls[1]), c("#fcf7f8", "#06d6a0", "#fcb0b3", "#f93943", "#7eb2dd"))
expect_equal(coolors2colors(urls[2]), c("#e06c53", "#ffba49", "#a3d9ff", "#d6efff", "#7e6b8f"))
expect_equal(coolors2colors(urls[3]), c("#ff5e5b", "#b9d8c2", "#ffffea", "#00cecb", "#ffed66"))
})

Loading…
Annulla
Salva