R/render-templates.R

Defines functions render_request pkgreview_request use_onboarding_tmpl pkgreview_readme_md pkgreview_index_rmd

Documented in pkgreview_index_rmd pkgreview_readme_md pkgreview_request render_request use_onboarding_tmpl

#' Create review templates.
#'
#' Creates skeleton review files:
#' \itemize{
#' \item `index.Rmd`: `html_notebook` to perform and record review in
#' \item `README.md`: prepopulated README for review repo.
#' }
#' `index.Rmd` will be automatically added to `.Rbuildignore`. The resulting templates are populated with default
#' YAML frontmatter and R fenced code chunks (`Rmd`).
#'
#' @param pkg_data package metadata generated by pkgreview_getdata()
#' @param template character string, one of `review` or `editor`.
#'
#' @export
# @importFrom usethis getFromNamespace check_installed
# @importFrom usethis getFromNamespace render_template
#' @examples
#' \dontrun{
#' pkg_data <- pkgreview_getdata(pkg_dir)
#' pkgreview_index_rmd(pkg_data)
#' pkgreview_readme_md(pkg_data)
#' }
pkgreview_index_rmd <- function(pkg_data,
                                template = c("review", "editor")) {
  template <- match.arg(template)

  usethis::use_template(
    glue::glue("{template}-index"),
    "index.Rmd",
    data = pkg_data,
    ignore = FALSE,
    open = FALSE,
    package = "pkgreviewr"
  )
  invisible(TRUE)
}

#' @export
#' @rdname pkgreview_index_rmd
pkgreview_readme_md <- function(pkg_data) {
  usethis::use_template(
    "review-README",
    "README.md",
    data = pkg_data,
    ignore = FALSE,
    open = FALSE,
    package = "pkgreviewr"
  )
}

#' Create software review/editor response template
#'
#' Clone an up to date copy of the specified ropensci software review/editor response template.
#' @param template character string, one of `review` or `editor`.
#'
#' @return writes a `{template}.md` checklist template file in the project root.
#' @export
#'
#' @examples
#' \dontrun{
#' use_onboarding_tmpl(template = "editor")
#' }
use_onboarding_tmpl <- function(template = c("review", "editor")) {
  template <- match.arg(template)
  tmpl_txt <- gh::gh("/repos/:owner/:repo/contents/:path",
    owner = "ropensci",
    repo = "dev_guide",
    path = glue::glue("templates/{template}.md")
  )

  tmpl_txt <- rawToChar(base64enc::base64decode(tmpl_txt$content))

  new <- usethis::write_over(
    usethis::proj_path(glue::glue("{template}.md")),
    tmpl_txt
  )
  invisible(new)
}



#' @export
#' @rdname pkgreview_index_rmd
pkgreview_request <- function(pkg_data) {
  pkg_data$editor <- gh::gh_whoami(usethis::github_token())$name

  usethis::use_template(
    "request",
    "request.Rmd",
    data = pkg_data,
    ignore = FALSE,
    open = FALSE,
    package = "pkgreviewr"
  )
}


#' Render request email body
#'
#' Launches an interactive input browser tab to complete required parameters:
#' - `reviewer_first_name`: reviewers first name
#' - `banter`: character string of custom greeting message
#' - `JOSS`: logical, whether review includes submission to JOSS
#' @return renders `request.Rmd` using parameters provided.
#' @export
#'
#' @examples
#' \dontrun{
#' render_request()
#' }
render_request <- function() {
    rmarkdown::render(usethis::proj_path("request.Rmd"),
                      params = "ask")
}
annakrystalli/pkgreviewr documentation built on Oct. 27, 2019, 4:22 a.m.