Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorise textVersion of bib entries #1507

Merged
merged 6 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions R/build-home-citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,14 @@ data_citations <- function(pkg = ".") {
cit <- read_citation(pkg$src_path)

text_version <- format(cit, style = "textVersion")
if (identical(text_version, "")) {
cit <- list(
html = format(cit, style = "html"),
bibtex = format(cit, style = "bibtex")
)
} else {
cit <- list(
html = paste0("<p>",text_version, "</p>"),
bibtex = format(cit, style = "bibtex")
)
}
cit <- list(
html = ifelse(text_version == "",
format(cit, style = "html"),
paste0("<p>", text_version, "</p>")),
bibtex = format(cit, style = "bibtex")
)

purrr::transpose(cit)
purrr::transpose(cit)
}

build_citation_authors <- function(pkg = ".") {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/assets/site-citation/multi/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: testpackage
Title: A test package
Version: 1.0.0
Author: Sebastian Meyer
Maintainer: Sebastian Meyer <noreply@example.org>
Description: Test multiple citations.
2 changes: 2 additions & 0 deletions tests/testthat/assets/site-citation/multi/inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bibentry("misc", title="Title One", author="Author One", year="2021")
bibentry("misc", title="Title Two", author="Author Two", year="2022")
9 changes: 9 additions & 0 deletions tests/testthat/test-build-citation-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ test_that("source link is added to citation page", {
lines <- read_lines(path(path, "docs", "authors.html"))
expect_true(any(grepl("<code>inst/CITATION</code></a></small>", lines)))
})

test_that("multiple citations all have HTML and BibTeX formats", {
path <- test_path("assets/site-citation/multi")
citations <- data_citations(path)
expect_length(citations, 2)
expect_true(all(lengths(citations) == 2))
hadley marked this conversation as resolved.
Show resolved Hide resolved
expect_true(all(rapply(citations, nchar) > 9))
hadley marked this conversation as resolved.
Show resolved Hide resolved
## html was "<p></p>" in pkgdown 1.6.1
})