Skip to content

Commit 70204d3

Browse files
authored
Prefer logo.svg if present (#1771)
Fixes #1640
1 parent c01bc95 commit 70204d3

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# roxygen2 (development version)
22

3+
* Package documentation now uses `logo.svg` if available, falling back to `logo.png` (#1640).
34
* `@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).
45
* `@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).
56
* `@description` no longer errors when the markdown text starts with a heading (#1705).

R/object-defaults.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ object_defaults.data <- function(x, block) {
4040
object_defaults.package <- function(x, block) {
4141
desc <- x$value$desc
4242

43-
logo_path <- file.path(x$value$path, "man", "figures", "logo.png")
43+
logo_path <- file.path(x$value$path, "man", "figures", "logo.svg")
44+
if (!file.exists(logo_path)) {
45+
logo_path <- file.path(x$value$path, "man", "figures", "logo.png")
46+
}
4447
if (file.exists(logo_path)) {
45-
fig <- "\\if{html}{\\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}\n\n"
48+
logo_file <- basename(logo_path)
49+
fig <- paste_c(
50+
c("\\if{html}{\\figure{", logo_file, "}"),
51+
"{options: style='float: right' alt='logo' width='120'}}\n\n"
52+
)
4653
} else {
4754
fig <- ""
4855
}

R/utils.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ uuid <- function(nchar = 8) {
214214
)
215215
}
216216

217+
paste_c <- function(...) {
218+
paste(c(...), collapse = "")
219+
}
220+
217221
# quoting -----------------------------------------------------------------
218222
auto_backtick <- function(x) {
219223
needs_backtick <- !has_quotes(x) & !is_syntactic(x)

tests/testthat/test-object-defaults.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,36 @@ test_that("can create package documentation", {
132132
expect_equal(out$get_value("docType"), "package")
133133
expect_equal(out$get_value("details"), "Details.")
134134
})
135+
136+
test_that("package doc prefers logo.svg over logo.png (#1640)", {
137+
path <- local_package_copy(test_path("empty"))
138+
desc::desc_set(
139+
file = path,
140+
Package = "roxygendevtest",
141+
Title = "Package Title",
142+
Description = "Package description."
143+
)
144+
block <- "
145+
#' @details Details.
146+
'_PACKAGE'
147+
"
148+
149+
# No logo
150+
withr::with_dir(path, blocks <- parse_text(block))
151+
out <- roclet_process(rd_roclet(), blocks)[[1]]
152+
expect_no_match(out$get_value("description"), "figure")
153+
154+
# Only png
155+
dir.create(file.path(path, "man", "figures"), recursive = TRUE)
156+
file.create(file.path(path, "man", "figures", "logo.png"))
157+
withr::with_dir(path, blocks <- parse_text(block, env = new.env()))
158+
out <- roclet_process(rd_roclet(), blocks)[[1]]
159+
expect_match(out$get_value("description"), "logo.png")
160+
161+
# Both svg and png: svg wins
162+
file.create(file.path(path, "man", "figures", "logo.svg"))
163+
withr::with_dir(path, blocks <- parse_text(block, env = new.env()))
164+
out <- roclet_process(rd_roclet(), blocks)[[1]]
165+
expect_match(out$get_value("description"), "logo.svg")
166+
expect_no_match(out$get_value("description"), "logo.png")
167+
})

0 commit comments

Comments
 (0)