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

Fix issue with bare google_font() passed to extra_fonts

tags/v0.3.0
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
240178f53a
3 измененных файлов: 45 добавлений и 1 удалений
  1. +1
    -1
      DESCRIPTION
  2. +3
    -0
      R/write_extra_css.R
  3. +41
    -0
      tests/testthat/test-write_extra_css.R

+ 1
- 1
DESCRIPTION Просмотреть файл

here, here,
knitr, knitr,
rmarkdown, rmarkdown,
testthat,
testthat (>= 2.1.0),
xaringan xaringan
VignetteBuilder: VignetteBuilder:
knitr knitr

+ 3
- 0
R/write_extra_css.R Просмотреть файл

} }


list2fonts <- function(fonts) { list2fonts <- function(fonts) {
if (inherits(fonts, "google_font")) {
fonts <- list(fonts)
}
fonts <- purrr::map_chr(fonts, function(f) { fonts <- purrr::map_chr(fonts, function(f) {
if (inherits(f, "google_font")) { if (inherits(f, "google_font")) {
f$url f$url

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

import <- function(x) paste0("@import url(", x, ");")

# test_that("list2fonts()", {})

describe("list2fonts()", {

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

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

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

it("handles list of google fonts", {
expect_equal(
list2fonts(list(google_font("Lato"), google_font("Work Sans"))),
import(c(lato_url, worksans_url))
)
})

it("handles mix of google_font() and bare string", {
expect_equal(
list2fonts(list(google_font("Lato"), worksans_url)),
import(c(lato_url, worksans_url))
)
})

it("handles bare google_font()", {
expect_equal(
list2fonts(google_font("Lato")),
import(lato_url)
)
})
})

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