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

tagQuery(): Relocate html deps to child objects #302

Merged
merged 8 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Bug fixes

* Closed #301: `tagQuery()` was failing to copy all `tagList()` html dependencies within nest child tag lists. (#302)
schloerke marked this conversation as resolved.
Show resolved Hide resolved

* Closed #290: htmltools previously did not specify which version of fastmap to use, and would fail to install with an old version of fastmap. (#291)

* `copyDependencyToDir()` no longer creates empty directories for dependencies that do not have any files. (@gadenbuie, #276)
Expand Down
11 changes: 10 additions & 1 deletion R/tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -1289,9 +1289,18 @@ flattenTagsRaw <- function(x) {
x
} else {
# For items that are lists (but not tags), recurse
ret <- unlist(lapply(x, flattenTagsRaw), recursive = FALSE)
flattened_tags <- lapply(x, flattenTagsRaw)
ret <- unlist(flattened_tags, recursive = FALSE)
# Copy over attributes put on the original list (ex: html deps)
mostattributes(ret) <- attributes(x)

# Copy over individual html deps into the final list from the flattened tags
# This does not work for attributes in general,
# but we can make it work for html deps
x_html_deps <- unlist(lapply(flattened_tags, htmlDependencies), recursive = FALSE)
if (length(x_html_deps) > 0) {
ret <- attachDependencies(ret, x_html_deps, append = TRUE)
}
ret
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-tag-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,30 @@ test_that("adding a class does not reorder attribs", {
)
})

test_that("tag list html deps are not lost when tag children are squashed", {
# https://github.com/rstudio/htmltools/issues/301

a_dep <- htmlDependency(name = "A", version = 1, src = "a.js")
b_dep <- htmlDependency(name = "B", version = 2, src = "b.js")
c_dep <- htmlDependency(name = "C", version = 3, src = "c.js")

children <-
attachDependencies(
list(
attachDependencies(list("X", "Y"), a_dep),
"Z"
),
list(b_dep, c_dep)
)

html <- div("test", children)
tq_html <- tagQuery(html)$allTags()

tq_deps <- findDependencies(tq_html$children)
expect_length(tq_deps, 3)
expect_equal(tq_deps, list(b_dep, c_dep, a_dep))
})




Expand Down