Procházet zdrojové kódy

Throw an error if c(font_string, google_font())

Closes #19
tags/v0.3.0
Garrick Aden-Buie před 6 roky
rodič
revize
4d421ae106
2 změnil soubory, kde provedl 23 přidání a 1 odebrání
  1. +10
    -0
      R/style_extra_css.R
  2. +13
    -1
      tests/testthat/test-write_extra_css.R

+ 10
- 0
R/style_extra_css.R Zobrazit soubor

} }


list2fonts <- function(fonts) { list2fonts <- function(fonts) {
if (
length(setdiff(names(google_font('fam')), names(fonts))) == 0 &&
!inherits(fonts, "google_font")
) {
# concatenating a string and a google_font() provides a wacky list
stop(
"Multiple fonts in `extra_fonts` must be specified inside a `list()`.",
call. = FALSE
)
}
if (inherits(fonts, "google_font")) { if (inherits(fonts, "google_font")) {
fonts <- list(fonts) fonts <- list(fonts)
} }

+ 13
- 1
tests/testthat/test-write_extra_css.R Zobrazit soubor

lato_url <- "https://fonts.googleapis.com/css?family=Lato" lato_url <- "https://fonts.googleapis.com/css?family=Lato"
worksans_url <- "https://fonts.googleapis.com/css?family=Work+Sans" worksans_url <- "https://fonts.googleapis.com/css?family=Work+Sans"


it("handles a list of font names", {
it("handles a list or c() of font urls", {
expect_equal( expect_equal(
list2fonts(list(lato_url, worksans_url)), list2fonts(list(lato_url, worksans_url)),
import(c(lato_url, worksans_url)) import(c(lato_url, worksans_url))
) )
expect_equal(list2fonts(c(lato_url, lato_url)), rep(import(lato_url), 2))
}) })


it("handles single character font name", { it("handles single character font name", {
import(lato_url) import(lato_url)
) )
}) })

it("throws an error when c() used to combine string and google_font()", {
expect_error(
list2fonts(c(lato_url, google_font("Lato"), google_font("Work Sans"))),
"Multiple fonts"
)
expect_error(
list2fonts(c(google_font("Lato"), google_font("Work Sans"))),
"Multiple fonts"
)
})
}) })

Načítá se…
Zrušit
Uložit