From 4c131f45c03b54c3f8d59a33243154e75f10b625 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 15 Mar 2024 14:21:34 -0400 Subject: [PATCH] Standardize messaging use pkgdown_config_href() when pkg is available. Recommend usethis::edit_pkgdown_config() otherwise. --- R/theme.R | 2 +- R/topics.R | 12 ++++++++---- R/utils-yaml.R | 5 +++-- tests/testthat/_snaps/utils-yaml.md | 7 +++++++ tests/testthat/test-utils-yaml.R | 5 ++--- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/R/theme.R b/R/theme.R index eb7e3f142..4d0c780c4 100644 --- a/R/theme.R +++ b/R/theme.R @@ -112,7 +112,7 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) { bs_version, pkgdown_field(pkg, c("template", "bootstrap")) ), - x = "Edit settings in {.file {pkgdown_config_relpath(pkg)}}" + x = "Edit settings in {pkgdown_config_href({pkg$src_path})}" ), call = caller_env()) } diff --git a/R/topics.R b/R/topics.R index 9bf17c9fa..6ff7a6781 100644 --- a/R/topics.R +++ b/R/topics.R @@ -10,8 +10,10 @@ select_topics <- function(match_strings, topics, check = FALSE) { # If none of the specified topics have a match, return no topics if (purrr::every(indexes, is_empty)) { if (check) { - cli::cli_abort( - "No topics matched in {.file _pkgdown.yml}. No topics selected.", + cli::cli_abort(c( + "No topics matched in pkgdown config. No topics selected.", + i = "Run {.run usethis::edit_pkgdown_config()} to edit." + ), call = caller_env() ) } @@ -177,8 +179,10 @@ match_eval <- function(string, env) { } topic_must <- function(message, topic, ..., call = NULL) { - cli::cli_abort( - "In {.file _pkgdown.yml}, topic must {message}, not {.val {topic}}.", + cli::cli_abort(c( + "Topic must {message}, not {.val {topic}}.", + i = "Run {.run usethis::edit_pkgdown_config()} to edit." + ), ..., call = call ) diff --git a/R/utils-yaml.R b/R/utils-yaml.R index ff8ece88d..eeee5ddd0 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -38,9 +38,10 @@ pkgdown_field <- function(pkg, fields, cfg = FALSE, fmt = FALSE) { } if (cfg) { - config_path <- pkgdown_config_relpath(pkg) if (fmt) { - config_path <- paste0("{.file ", config_path, "}") + config_path <- pkgdown_config_href(pkg$src_path) + } else { + config_path <- cli::format_inline(pkgdown_config_relpath(pkg)) } paste0(flds, " in ", config_path) diff --git a/tests/testthat/_snaps/utils-yaml.md b/tests/testthat/_snaps/utils-yaml.md index 2f000754a..d7e401cea 100644 --- a/tests/testthat/_snaps/utils-yaml.md +++ b/tests/testthat/_snaps/utils-yaml.md @@ -1,5 +1,12 @@ # pkgdown_field produces useful description + Code + cli::cli_inform(pkgdown_field(pkg, c("a"), cfg = TRUE, fmt = TRUE)) + Message + a in _pkgdown.yml + +--- + Code check_yaml_has("x", where = "a", pkg = pkg) Condition diff --git a/tests/testthat/test-utils-yaml.R b/tests/testthat/test-utils-yaml.R index 20477723f..c18d1dd39 100644 --- a/tests/testthat/test-utils-yaml.R +++ b/tests/testthat/test-utils-yaml.R @@ -7,9 +7,8 @@ test_that("pkgdown_field produces useful description", { expect_equal(pkgdown_field(pkg, c("a", "b")), "a.b") expect_equal(pkgdown_field(pkg, c("a", "b"), fmt = TRUE), "{.field a.b}") expect_equal(pkgdown_field(pkg, c("a"), cfg = TRUE), "a in _pkgdown.yml") - expect_equal( - pkgdown_field(pkg, c("a"), cfg = TRUE, fmt = TRUE), - "{.field a} in {.file _pkgdown.yml}" + expect_snapshot( + cli::cli_inform(pkgdown_field(pkg, c("a"), cfg = TRUE, fmt = TRUE)) ) expect_snapshot(error = TRUE, {