Skip to content

Commit

Permalink
Rename pkgdown_field to config_field
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 3, 2024
1 parent c740f0b commit 72fcd00
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions R/build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ data_home_sidebar_authors <- function(pkg = ".") {
bullets <- c(
markdown_text_inline(
pkg$meta$authors$sidebar$before,
pkgdown_field(c("authors", "sidebar", "before"))
config_field(c("authors", "sidebar", "before"))
),
authors,
markdown_text_inline(
pkg$meta$authors$sidebar$after,
pkgdown_field(c("authors", "sidebar", "after"))
config_field(c("authors", "sidebar", "after"))
)
)

Expand Down Expand Up @@ -96,7 +96,7 @@ author_name <- function(x, authors, pkg) {
if (!is.null(author$html)) {
name <- markdown_text_inline(
author$html,
pkgdown_field(c("authors", name, "html"))
config_field(c("authors", name, "html"))
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {
if (!file.exists(html_path)) {
rel_html_path <- fs::path_rel(html_path, pkg$src_path)

msg_fld <- pkgdown_field(c('home', 'sidebar', 'html'), fmt = TRUE)
msg_fld <- config_field(c('home', 'sidebar', 'html'), fmt = TRUE)

config_abort(pkg,
c(
Expand Down
4 changes: 2 additions & 2 deletions R/build-redirects.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ build_redirects <- function(pkg = ".",

cli::cli_rule("Building redirects")
if (is.null(pkg$meta$url)) {
msg_fld <- pkgdown_field("url", fmt = TRUE)
msg_fld <- config_field("url", fmt = TRUE)
config_abort(
pkg,
paste0(msg_fld, " is required to generate redirects.")
Expand All @@ -54,7 +54,7 @@ build_redirects <- function(pkg = ".",

build_redirect <- function(entry, index, pkg) {
if (!is.character(entry) || length(entry) != 2) {
msg_fld <- pkgdown_field("redirects")
msg_fld <- config_field("redirects")
config_abort(
pkg,
"{.field {msg_fld}[[{index}]]} must be a character vector of length 2.",
Expand Down
6 changes: 3 additions & 3 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ get_bootstrap_version <- function(template, config_path = NULL, package = NULL)
c(
sprintf(
"Both {.field %s} and {.field %s} are set.",
pkgdown_field(c("template", "bootstrap")),
pkgdown_field(c("template", "bslib", "version"))
config_field(c("template", "bootstrap")),
config_field(c("template", "bslib", "version"))
),
i = instructions
),
Expand All @@ -168,7 +168,7 @@ check_bootstrap_version <- function(version, pkg) {
cli::cli_warn("{.var bootstrap: 4} no longer supported, using {.var bootstrap: 5} instead")
5
} else {
msg_fld <- pkgdown_field(c("template", "bootstrap"), fmt = TRUE)
msg_fld <- config_field(c("template", "bootstrap"), fmt = TRUE)
config_abort(
pkg,
c(
Expand Down
2 changes: 1 addition & 1 deletion R/sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkgdown_sitrep <- function(pkg = ".") {
warns <- c()

if (is.null(pkg$meta[["url"]])) {
msg_fld <- pkgdown_field("url", fmt = TRUE)
msg_fld <- config_field("url", fmt = TRUE)
warns <- c(warns, x = paste0(msg_fld, " is absent. See {.vignette pkgdown::metadata}."))
}

Expand Down
4 changes: 2 additions & 2 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ check_bslib_theme <- function(theme, pkg, field = c("template", "bootswatch"), b
sprintf(
"Can't find Bootswatch or bslib theme preset {.val %s} ({.field %s}) for Bootstrap version {.val %s} ({.field %s}).",
theme,
pkgdown_field(field),
config_field(field),
bs_version,
pkgdown_field(c("template", "bootstrap"))
config_field(c("template", "bootstrap"))
),
call = caller_env()
)
Expand Down
8 changes: 4 additions & 4 deletions R/utils-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ check_yaml_has <- function(missing, where, pkg, call = caller_env()) {
}

missing_components <- lapply(missing, function(x) c(where, x))
msg_flds <- pkgdown_field(missing_components)
msg_flds <- config_field(missing_components)

config_abort(
pkg,
Expand All @@ -21,7 +21,7 @@ yaml_character <- function(pkg, where) {
} else if (is.character(x)) {
x
} else {
fld <- pkgdown_field(where, fmt = TRUE)
fld <- config_field(where, fmt = TRUE)
config_abort(
pkg,
paste0(fld, " must be a character vector."),
Expand All @@ -30,7 +30,7 @@ yaml_character <- function(pkg, where) {
}
}

pkgdown_field <- function(fields, fmt = FALSE) {
config_field <- function(fields, fmt = FALSE) {
if (!is.list(fields)) fields <- list(fields)

flds <- purrr::map_chr(fields, ~ paste0(.x, collapse = "."))
Expand Down Expand Up @@ -67,7 +67,7 @@ config_path <- function(pkg) {
# print helper ------------------------------------------------------------

print_yaml <- function(x) {
structure(x, class = "print_yaml")
structure(x, class = "print_yµaml")
}
#' @export
print.print_yaml <- function(x, ...) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/utils-yaml.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pkgdown_field produces useful description
# config_field produces useful description

Code
check_yaml_has("x", where = "a", pkg = pkg)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-utils-yaml.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_that("pkgdown_field produces useful description", {
test_that("config_field produces useful description", {
pkg <- local_pkgdown_site()
file_touch(file.path(pkg$src_path, "_pkgdown.yml"))

expect_equal(pkgdown_field(c("a", "b")), "a.b")
expect_equal(pkgdown_field(c("a", "b"), fmt = TRUE), "{.field a.b}")
expect_equal(config_field(c("a", "b")), "a.b")
expect_equal(config_field(c("a", "b"), fmt = TRUE), "{.field a.b}")

expect_snapshot(error = TRUE, {
check_yaml_has("x", where = "a", pkg = pkg)
Expand Down

0 comments on commit 72fcd00

Please sign in to comment.