forked from r-lib/gert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroxygen2.R
More file actions
69 lines (62 loc) · 2.11 KB
/
Copy pathroxygen2.R
File metadata and controls
69 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# nocov start
git_links <- function() {
base_url <- "https://libgit2.org/docs/reference/main/%s/index.html"
dat <- as.data.frame(
rbind(
c("branch", sprintf(base_url, "branch")),
c("cherrypick", sprintf(base_url, "cherrypick")),
c("checkout", sprintf(base_url, "checkout")),
c("clone", sprintf(base_url, "clone")),
c("commit", sprintf(base_url, "commit")),
c("config", sprintf(base_url, "config")),
c("diff", sprintf(base_url, "diff")),
c("graph", sprintf(base_url, "graph")),
c("ignore", sprintf(base_url, "ignore")),
c("index", sprintf(base_url, "index")),
c("merge", sprintf(base_url, "merge")),
c("rebase", sprintf(base_url, "rebase")),
c("remote", sprintf(base_url, "remote")),
c("repository", sprintf(base_url, "repository")),
c("reset", sprintf(base_url, "reset")),
c("revert", sprintf(base_url, "revert")),
c("signature", sprintf(base_url, "signature")),
c("stash", sprintf(base_url, "stash")),
c("status", sprintf(base_url, "status")),
c("submodule", sprintf(base_url, "submodule")),
c("tag", sprintf(base_url, "tag")),
c("worktree", sprintf(base_url, "worktree"))
),
stringsAsFactors = FALSE
)
names(dat) <- c("command", "url")
dat
}
#' @exportS3Method roxygen2::roxy_tag_parse
roxy_tag_parse.roxy_tag_git <- function(x) {
roxygen2::tag_words(x)
}
#' @exportS3Method roxygen2::roxy_tag_rd
roxy_tag_rd.roxy_tag_git <- function(x, base_path, env) {
roxygen2::rd_section("gitcommands", x$val)
}
#' @export
format.rd_section_gitcommands <- function(x, ...) {
paste0(
"\\section{Related libgit2 documentation}{",
present_git_link(x[["value"]]),
".}\n"
)
}
present_git_link <- function(value) {
links <- git_links()
format_git_single_link <- function(x) {
df <- links[links$command == x, ]
if (nrow(df) == 0) {
warning(sprintf("Can't find libgit2 entry for %s!", x))
}
sprintf("\\href{%s}{\\code{%s}}", df$url, df$command)
}
strings <- vapply(unique(value), format_git_single_link, character(1))
paste(strings, collapse = ", ")
}
# nocov end