Skip to content

Commit 7d6a34e

Browse files
committed
docs: tag
1 parent 1113305 commit 7d6a34e

5 files changed

Lines changed: 93 additions & 2 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ Imports:
2323
sys,
2424
zip (>= 2.1.0)
2525
Suggests:
26-
spelling,
26+
spelling,
2727
knitr,
2828
rmarkdown,
29-
testthat
29+
testthat,
30+
roxygen2
3031
VignetteBuilder:
3132
knitr
3233
Encoding: UTF-8

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(format,rd_section_gitcommands)
34
S3method(print,gert_signature)
45
S3method(print,git_repo_ptr)
6+
S3method(roxygen2,roxy_tag_parse)
7+
S3method(roxygen2,roxy_tag_rd)
58
export(git_add)
69
export(git_ahead_behind)
710
export(git_archive_zip)

R/branch.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ git_branch_list <- function(local = NULL, repo = '.') {
2828
#' @param force ignore conflicts and overwrite modified files
2929
#' @param orphan if branch does not exist, checkout unborn branch
3030
#' @useDynLib gert R_git_checkout_branch R_git_checkout_unborn
31+
#' @git checkout
3132
git_branch_checkout <- function(
3233
branch,
3334
force = FALSE,

R/gert-package.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,42 @@
44
## usethis namespace: start
55
## usethis namespace: end
66
NULL
7+
8+
.onLoad <- function(libname, pkgname) {
9+
register_s3_method(
10+
"roxygen2",
11+
"roxy_tag_parse",
12+
"roxy_tag_git",
13+
roxy_tag_parse.roxy_tag_git
14+
)
15+
register_s3_method(
16+
"roxygen2",
17+
"roxy_tag_rd",
18+
"roxy_tag_git",
19+
roxy_tag_rd.roxy_tag_git
20+
)
21+
}
22+
23+
24+
register_s3_method <- function(pkg, generic, class, fun = NULL) {
25+
stopifnot(is.character(pkg), length(pkg) == 1)
26+
stopifnot(is.character(generic), length(generic) == 1)
27+
stopifnot(is.character(class), length(class) == 1)
28+
if (is.null(fun)) {
29+
fun <- get(paste0(generic, ".", class), envir = parent.frame())
30+
} else {
31+
stopifnot(is.function(fun))
32+
}
33+
34+
if (isNamespaceLoaded(pkg)) {
35+
registerS3method(generic, class, fun, envir = asNamespace(pkg))
36+
}
37+
38+
# Always register hook in case package is later unloaded & reloaded
39+
setHook(
40+
packageEvent(pkg, "onLoad"),
41+
function(...) {
42+
registerS3method(generic, class, fun, envir = asNamespace(pkg))
43+
}
44+
)
45+
}

R/roxygen2.R

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# nocov start
2+
3+
git_links <- function() {
4+
rlang::check_installed("tibble")
5+
tibble::tribble(
6+
~command , ~url ,
7+
"checkout" , "https://libgit2.org/docs/reference/main/checkout/index.html"
8+
)
9+
}
10+
11+
#' @exportS3Method roxygen2 roxy_tag_parse
12+
roxy_tag_parse.roxy_tag_git <- function(x) {
13+
roxygen2::tag_words(x)
14+
}
15+
16+
#' @exportS3Method roxygen2 roxy_tag_rd
17+
roxy_tag_rd.roxy_tag_git <- function(x, base_path, env) {
18+
roxygen2::rd_section("gitcommands", x$val)
19+
}
20+
21+
#' @export
22+
format.rd_section_gitcommands <- function(x, ...) {
23+
paste0(
24+
"\\section{Related libgit2 documentation}{",
25+
present_git_link(x[["value"]]),
26+
".}\n"
27+
)
28+
}
29+
30+
present_git_link <- function(value) {
31+
format_git_single_link <- function(x, git_links) {
32+
df <- git_links[git_links$command == x, ]
33+
if (nrow(df) == 0) {
34+
cli::cli_warn("Can't find libgit2 entry for {x}!")
35+
}
36+
sprintf("\\href{%s}{\\code{%s}}", df$command, df$name)
37+
}
38+
39+
strings <- purrr::map_chr(
40+
unique(value),
41+
format_git_single_link,
42+
git_links = git_links()
43+
)
44+
45+
paste(strings, collapse = ", ")
46+
}
47+
# nocov end

0 commit comments

Comments
 (0)