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

Inform user when bslib files are created #2525

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ build_bslib <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)
bs_theme <- bs_theme(pkg)

cur_deps <- find_deps(pkg)
cur_digest <- purrr::map_chr(cur_deps, file_digest)

deps <- bslib::bs_theme_dependencies(bs_theme)
deps <- lapply(deps, htmltools::copyDependencyToDir, file.path(pkg$dst_path, "deps"))
deps <- lapply(deps, htmltools::makeDependencyRelative, pkg$dst_path)

new_deps <- find_deps(pkg)
new_digest <- purrr::map_chr(cur_deps, file_digest)

all_deps <- union(new_deps, cur_deps)
diff <- cur_digest[all_deps] == new_digest[all_deps]
hadley marked this conversation as resolved.
Show resolved Hide resolved
changed <- all_deps[!diff | is.na(diff)]

if (length(changed) > 0) {
purrr::walk(changed, function(dst) {
cli::cli_inform("Updating {dst_path(path_rel(dst, pkg$dst_path))}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not a single message with all files updated?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with an itemized list maybe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that would be inconsistent with our other messages 😄

})
}

head <- htmltools::renderDependencies(deps, srcType = "file")
write_lines(head, data_deps_path(pkg))
}
Expand All @@ -31,6 +47,15 @@ data_deps_path <- function(pkg) {
file.path(pkg$dst_path, "deps", "data-deps.txt")
}

find_deps <- function(pkg) {
deps_path <- path(pkg$dst_path, "deps")
if (!dir_exists(deps_path)) {
character()
} else {
dir_ls(deps_path, type = "file", recurse = TRUE)
}
}

bs_theme <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
Copying <pkgdown>/BS3/assets/pkgdown.js to pkgdown.js
Copying pkgdown/extra.css to extra.css

---

Code
init_site(pkg)
Message
-- Initialising site -----------------------------------------------------------
Copying <pkgdown>/BS5/assets/link.svg to link.svg
Copying <pkgdown>/BS5/assets/pkgdown.js to pkgdown.js
Copying pkgdown/extra.css to extra.css
Updating deps/bootstrap-5.3.1/bootstrap.bundle.min.js
Updating deps/bootstrap-5.3.1/bootstrap.bundle.min.js.map
Updating deps/bootstrap-5.3.1/bootstrap.min.css
Updating deps/jquery-3.6.0/jquery-3.6.0.js
Updating deps/jquery-3.6.0/jquery-3.6.0.min.js
Updating deps/jquery-3.6.0/jquery-3.6.0.min.map

# site meta doesn't break unexpectedly

Code
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
test_that("informative print method", {
pkg <- local_pkgdown_site(test_path("assets/init-extra-1"))
expect_snapshot(init_site(pkg))

pkg <- local_pkgdown_site(test_path("assets/init-extra-1"), meta = "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me realise that many of the tests are using BS 3 sites. I wonder if we should change them all to BS5.

template:
bootstrap: 5
")
expect_snapshot(init_site(pkg))
})

test_that("extra.css and extra.js copied and linked", {
Expand Down
Loading