Skip to content

Commit

Permalink
+ link_*
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Feb 26, 2024
1 parent be03aae commit 1572de5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(auto)
export(link_call)
export(link_pkg)
export(tip_call)
export(tip_pkg)
importFrom(htmltools,tags)
29 changes: 21 additions & 8 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ get_title <- function(url) {

#' @rdname auto
#' @export
tip_pkg <- function(pkg, keep_braces = TRUE, text = get_title(url), ...) {
link_pkg <- function(pkg, keep_braces = TRUE) {
url <- downlit::href_package(pkg)
link_text <- if (keep_braces) "{{{pkg}}}" else "{pkg}"
tags$a(glue::glue(link_text), href = url, class = "r-link-pkg")
}

#' @rdname auto
#' @export
tip_pkg <- function(pkg, keep_braces = TRUE, text = get_title(url), ...) {
bslib::tooltip(
tags$a(glue::glue(link_text), href = url, class = "r-link-pkg"),
link_pkg(pkg, keep_braces = keep_braces),
text,
...
)
}

#' @rdname auto
#' @export
tip_call <- function(call, keep_pkg_prefix = TRUE, text = get_title(url), ...) {
link_call <- function(call, keep_pkg_prefix = TRUE) {
url <- downlit::autolink_url(call)

link_text <- if (keep_pkg_prefix) {
Expand All @@ -35,12 +41,17 @@ tip_call <- function(call, keep_pkg_prefix = TRUE, text = get_title(url), ...) {
glue::glue("{fun}()", fun = stringr::str_extract(call, rx_call, group = 2))
}

tags$a(link_text, href = url, class = "r-link-call")
}

#' @rdname auto
#' @export
tip_call <- function(call, keep_pkg_prefix = TRUE, text = get_title(url), ...) {
bslib::tooltip(
tags$a(link_text, href = url, class = "r-link-call"),
link_call(call, keep_pkg_prefix = keep_pkg_prefix),
text,
...
)

}

autolink_pkg <- function(x, keep_braces = TRUE) {
Expand Down Expand Up @@ -79,12 +90,14 @@ autolink_call <- function(x, keep_pkg_prefix = TRUE) {
#'
#' # manually generate the tooltips for {pkg} and pkg::fun()
#' tip_pkg("tidyverse")
#' link_pkg("tidyverse")
#'
#' tip_call("dplyr::summarise()")
#' link_call("dplyr::summarise()")
#' }
#'
#' # You typically don't need to supply the text, but you can
#' tip_pkg("tidyverse", text = "The tidyverse")
#' tip_call("dplyr::summarise()", text = "Summarise each group down to one row")
#' link_pkg("tidyverse")
#' link_call("dplyr::summarise()")
#'
#' @export
auto <- function(keep_braces = TRUE, keep_pkg_prefix = TRUE) {
Expand Down
16 changes: 12 additions & 4 deletions man/auto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1572de5

Please sign in to comment.