Skip to content

Commit

Permalink
Standardize messaging
Browse files Browse the repository at this point in the history
use pkgdown_config_href() when pkg is available.

Recommend usethis::edit_pkgdown_config() otherwise.
  • Loading branch information
olivroy committed Mar 15, 2024
1 parent 14ab561 commit 4c131f4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
12 changes: 8 additions & 4 deletions R/topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions R/utils-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/utils-yaml.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-utils-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 4c131f4

Please sign in to comment.