R/build-home-license.R

Defines functions licenses_db autolink_license

licenses_db <- function() {
  path <- file.path(R.home("share"), "licenses", "license.db")
  db <- tibble::as_tibble(read.dcf(path))

  abbr <- ifelse(is.na(db$SSS), db$Abbrev, db$SSS)
  url <- db$URL

  # Add entry for LICENSE file
  abbr <- c(abbr, "LICENSE")
  url <- c(url, "LICENSE.html")

  out <- tibble::tibble(abbr, url)
  out[!is.na(out$abbr), ]
}

autolink_license <- function(x) {
  db <- licenses_db()
  db$a <- paste0("<a href='", db$url, "'>", db$abbr, "</a>")

  for (i in seq_len(nrow(db))) {
    match <- paste0("\\b\\Q", db$abbr[[i]], "\\E\\b")
    x <- gsub(match, db$a[[i]], x, perl = TRUE)
  }
  x
}
Laurae2/pkgdown documentation built on May 27, 2019, 12:17 p.m.