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

Only extract lifecycle badges from description #2592

Merged
merged 1 commit into from
May 28, 2024
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pkgdown (development version)

* `build_reference_index()` now displays lifecycle badges next to the function name (#2123). You can now also use `has_lifecycle()` to select functions by their lifecycle status.
* `build_reference_index()` now displays function lifecycle badges next to the function name (#2123). The badges are extracted only from the function description. You can now also use `has_lifecycle()` to select functions by their lifecycle status.
* `build_articles()` now recognises a new `external-articles` top-level field that allows you to define articles that live in other packages (#2028).
* New light switch makes it easy for users to switch between light and dark themes for the website (based on work in bslib by @gadenbuie). For now this behaviour is opt-in with `template.light-switch: true` but in the future we may turn it on automatically. See the customization vignette for details (#1696).
* The search dropdown has been tweaked to look more like the other navbar menu items (#2338).
Expand Down
4 changes: 3 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ extract_source <- function(x) {
}

extract_lifecycle <- function(x) {
fig <- extract_figure(x)
desc <- purrr::keep(x, inherits, "tag_description")
fig <- extract_figure(desc)

if (!is.null(fig) && length(fig) > 0 && length(fig[[1]]) > 0) {
path <- as.character(fig[[1]][[1]])
if (grepl("lifecycle", path)) {
Expand Down
15 changes: 11 additions & 4 deletions tests/testthat/test-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ test_that("read_meta() errors gracefully if _pkgdown.yml failed to parse", {

# lifecycle ---------------------------------------------------------------

test_that("can extract lifecycle badges", {
expect_equal(
extract_lifecycle(rd_text(lifecycle::badge("deprecated"))),
"deprecated"
test_that("can extract lifecycle badges from description", {
rd_desc <- rd_text(
paste0("\\description{", lifecycle::badge("deprecated"), "}"),
fragment = FALSE
)
rd_param <- rd_text(
paste0("\\arguments{\\item{pkg}{", lifecycle::badge("deprecated"), "}}"),
fragment = FALSE
)

expect_equal(extract_lifecycle(rd_desc), "deprecated")
expect_equal(extract_lifecycle(rd_param), NULL)
})

test_that("malformed figures fail gracefully", {
Expand Down
Loading