Skip to content

Commit

Permalink
move around
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Feb 26, 2024
1 parent 1094586 commit cab5252
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Imports:
rlang,
stringr,
xml2
URL: https://github.com/tadascience/link, https://link.tada.science/
URL: https://link.tada.science/, https://github.com/tadascience/link
BugReports: https://github.com/tadascience/link/issues
98 changes: 49 additions & 49 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,55 @@ rx_valid_fun <- "([a-zA-Z]\\w*|\\.\\w+)"
rx_pkg <- glue::glue("[{{]({rx_valid_pkg})[}}]")
rx_call <- glue::glue("({rx_valid_pkg})::({rx_valid_fun})\\(\\)")

#' Setup automatic linking
#'
#' @param type "plain" for plain links, "tooltip" for adding a tooltip
#' @param keep_braces Should the braces be kept ?
#' @param keep_pkg_prefix Should the package prefix be kept ?
#' @param pkg package name
#' @param call Function call of the form `pkg::fun()`
#' @param ... See [bslib::tooltip()]
#'
#' @examples
#'
#' \dontrun{
#' # auto is mostly meant to be called inside rmarkdown or quarto documents
#' auto()
#' auto(keep_braces = FALSE, keep_pkg_prefix = FALSE)
#'
#' # manually generate the tooltips for {pkg} and pkg::fun()
#' link::to_pkg("tidyverse")
#' link::to_pkg("tidyverse")
#'
#' link::to_call("dplyr::summarise()")
#' link::to_call("dplyr::summarise()")
#' }
#'
#' link::to_pkg("tidyverse", type = "plain")
#' link::to_call("dplyr::summarise()", type = "plain")
#'
#' @export
auto <- function(type = c("tooltip", "plain"), keep_braces = TRUE, keep_pkg_prefix = TRUE) {
type <- rlang::arg_match(type)
default_text_hook <- knitr::knit_hooks$get("text")
knitr::knit_hooks$set(text = function(x) {

x <- autolink_pkg(x, type = type, keep_braces = keep_braces)
x <- autolink_call(x, type = type, keep_pkg_prefix = keep_pkg_prefix)

default_text_hook(x)
})

# This is a hack because I currently don't know how to inject the
# dependencies otherwise
switch(
type,
tooltip = bslib::tooltip("", ""),

invisible(NULL)
)
}

get_title <- function(url) {
httr2::request(url) |>
httr2::req_perform() |>
Expand Down Expand Up @@ -66,52 +115,3 @@ autolink_call <- function(x, type, keep_pkg_prefix = TRUE) {
}
)
}

#' Setup automatic linking
#'
#' @param type "plain" for plain links, "tooltip" for adding a tooltip
#' @param keep_braces Should the braces be kept ?
#' @param keep_pkg_prefix Should the package prefix be kept ?
#' @param pkg package name
#' @param call Function call of the form `pkg::fun()`
#' @param ... See [bslib::tooltip()]
#'
#' @examples
#'
#' \dontrun{
#' # auto is mostly meant to be called inside rmarkdown or quarto documents
#' auto()
#' auto(keep_braces = FALSE, keep_pkg_prefix = FALSE)
#'
#' # manually generate the tooltips for {pkg} and pkg::fun()
#' link::to_pkg("tidyverse")
#' link::to_pkg("tidyverse")
#'
#' link::to_call("dplyr::summarise()")
#' link::to_call("dplyr::summarise()")
#' }
#'
#' link::to_pkg("tidyverse", type = "plain")
#' link::to_call("dplyr::summarise()", type = "plain")
#'
#' @export
auto <- function(type = c("tooltip", "plain"), keep_braces = TRUE, keep_pkg_prefix = TRUE) {
type <- rlang::arg_match(type)
default_text_hook <- knitr::knit_hooks$get("text")
knitr::knit_hooks$set(text = function(x) {

x <- autolink_pkg(x, type = type, keep_braces = keep_braces)
x <- autolink_call(x, type = type, keep_pkg_prefix = keep_pkg_prefix)

default_text_hook(x)
})

# This is a hack because I currently don't know how to inject the
# dependencies otherwise
switch(
type,
tooltip = bslib::tooltip("", ""),

invisible(NULL)
)
}

0 comments on commit cab5252

Please sign in to comment.