Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# roxygen2 (development version)

* Package documentation now uses `logo.svg` if available, falling back to `logo.png` (#1640).
* `@family` no longer adds a trailing space after the colon in the default family prefix (#1628). Custom `rd_family_title` values now automatically get a colon appended if they don't already end with one (#1656).
* `@inheritDotParams` now warns and produces no output when there are no parameters to inherit, instead of generating an empty `\describe` block that caused CRAN HTML validation warnings (#1671).
* `@description` no longer errors when the markdown text starts with a heading (#1705).
Expand Down
11 changes: 9 additions & 2 deletions R/object-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ object_defaults.data <- function(x, block) {
object_defaults.package <- function(x, block) {
desc <- x$value$desc

logo_path <- file.path(x$value$path, "man", "figures", "logo.png")
logo_path <- file.path(x$value$path, "man", "figures", "logo.svg")
if (!file.exists(logo_path)) {
logo_path <- file.path(x$value$path, "man", "figures", "logo.png")
}
if (file.exists(logo_path)) {
fig <- "\\if{html}{\\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}\n\n"
logo_file <- basename(logo_path)
fig <- paste_c(
c("\\if{html}{\\figure{", logo_file, "}"),
"{options: style='float: right' alt='logo' width='120'}}\n\n"
)
} else {
fig <- ""
}
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ uuid <- function(nchar = 8) {
)
}

paste_c <- function(...) {
paste(c(...), collapse = "")
}

# quoting -----------------------------------------------------------------
auto_backtick <- function(x) {
needs_backtick <- !has_quotes(x) & !is_syntactic(x)
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test-object-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,36 @@ test_that("can create package documentation", {
expect_equal(out$get_value("docType"), "package")
expect_equal(out$get_value("details"), "Details.")
})

test_that("package doc prefers logo.svg over logo.png (#1640)", {
path <- local_package_copy(test_path("empty"))
desc::desc_set(
file = path,
Package = "roxygendevtest",
Title = "Package Title",
Description = "Package description."
)
block <- "
#' @details Details.
'_PACKAGE'
"

# No logo
withr::with_dir(path, blocks <- parse_text(block))
out <- roclet_process(rd_roclet(), blocks)[[1]]
expect_no_match(out$get_value("description"), "figure")

# Only png
dir.create(file.path(path, "man", "figures"), recursive = TRUE)
file.create(file.path(path, "man", "figures", "logo.png"))
withr::with_dir(path, blocks <- parse_text(block, env = new.env()))
out <- roclet_process(rd_roclet(), blocks)[[1]]
expect_match(out$get_value("description"), "logo.png")

# Both svg and png: svg wins
file.create(file.path(path, "man", "figures", "logo.svg"))
withr::with_dir(path, blocks <- parse_text(block, env = new.env()))
out <- roclet_process(rd_roclet(), blocks)[[1]]
expect_match(out$get_value("description"), "logo.svg")
expect_no_match(out$get_value("description"), "logo.png")
})