diff --git a/DESCRIPTION b/DESCRIPTION index 02bc12b..233097b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,7 +33,6 @@ Imports: openssl, pkgdown, processx, - rematch2, sessioninfo, usethis, withr, diff --git a/NAMESPACE b/NAMESPACE index f0630ef..80e72f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,7 +62,6 @@ importFrom(magrittr,"%>%") importFrom(openssl,base64_decode) importFrom(pkgdown,build_site) importFrom(processx,run) -importFrom(rematch2,re_match) importFrom(sessioninfo,package_info) importFrom(tools,toTitleCase) importFrom(usethis,use_description) diff --git a/R/deploy_site_github_with_extra_files.R b/R/deploy_site_github_with_extra_files.R index e8fe796..06b7609 100644 --- a/R/deploy_site_github_with_extra_files.R +++ b/R/deploy_site_github_with_extra_files.R @@ -127,7 +127,6 @@ github_push <- function(dir, commit_message) { #' folder to "gh-pages" #' @export #' @importFrom fs dir_create file_temp dir_delete file_chmod -#' @importFrom rematch2 re_match #' @importFrom pkgdown build_site #' @importFrom callr rcmd #' @importFrom openssl base64_decode @@ -271,7 +270,7 @@ deploy_to_branch_with_extra_files <- function(pkg = ".", ) if (github_pages) { - getFromNamespace("build_github_pages", "pkgdown")(pkg) + get_from_namespace("build_github_pages", "pkgdown")(pkg) } github_push(dest_dir, commit_message, remote, branch) diff --git a/R/get_markdown_for_index_or_readme.R b/R/get_markdown_for_index_or_readme.R new file mode 100644 index 0000000..5709d1c --- /dev/null +++ b/R/get_markdown_for_index_or_readme.R @@ -0,0 +1,62 @@ +# get_markdown_for_index_or_readme --------------------------------------------- + +#' @importFrom kwb.utils selectElements +get_markdown_for_index_or_readme <- function( + is_readme, + user = "KWB-R", + domain = "github", + stage = "experimental" +) +{ + pkg <- read_description() + + name <- kwb.utils::selectElements(pkg, "name") + + doc_lines <- if (is_readme) { + markdown_documentation_links(user, domain, name = name) + } + + title_lines <- if (is_readme) { + c("", sprintf("# %s", pkg$name)) + } + + c( + use_badge_ghactions(name, user), + use_badge_codecov(name, user, domain), + use_badge_lifecycle(stage), + use_badge_cran(name), + use_badge_runiverse(name), + title_lines, + "", + pkg$desc, + "", + use_installation(name, user, domain), + doc_lines + ) +} + +# markdown_documentation_links ------------------------------------------------- +markdown_documentation_links <- function(user, domain, name) +{ + url_release <- sprintf( + "https://%s.%s.io/%s", + tolower(user), + tolower(domain), + tolower(name) + ) + + c( + "", + "## Documentation", + "", + paste("Release:", markdown_link(url_release)), + "", + paste("Development:", markdown_link(paste0(url_release, "/dev"))) + ) +} + +# markdown_link ---------------------------------------------------------------- +markdown_link <- function(x) +{ + sprintf("[%s](%s)", x, x) +} diff --git a/R/use_badges.R b/R/use_badges.R index d83ee98..0e7dabd 100644 --- a/R/use_badges.R +++ b/R/use_badges.R @@ -140,7 +140,7 @@ use_badge_codecov <- function(repo = NULL, user = "KWB-R", domain = "github") #' @export use_badge_lifecycle <- function(stage = "experimental") { - stages <- getFromNamespace("stages", "usethis") + stages <- get_from_namespace("stages", "usethis") stage <- match.arg(tolower(stage), names(stages)) kwb.utils::resolve( diff --git a/R/use_codecov.R b/R/use_codecov.R index d824391..70b5be8 100644 --- a/R/use_codecov.R +++ b/R/use_codecov.R @@ -6,8 +6,8 @@ #' @export use_codecov <- function() { - getFromNamespace("check_uses_github_actions", "usethis")() - getFromNamespace("use_dependency", "usethis")("covr", "Suggests") + get_from_namespace("check_uses_github_actions", "usethis")() + get_from_namespace("use_dependency", "usethis")("covr", "Suggests") if (! usethis::use_template("codecov.yml", ignore = TRUE)) { return(invisible(FALSE)) diff --git a/R/use_index_md.R b/R/use_index_md.R index ab50a5a..7c24904 100644 --- a/R/use_index_md.R +++ b/R/use_index_md.R @@ -13,26 +13,20 @@ #' @importFrom desc desc use_index_md <- function( - user = "KWB-R", domain = "github", stage = "experimental" + user = "KWB-R", + domain = "github", + stage = "experimental" ) { - pkg <- read_description() - - index_md <- c( - use_badge_ghactions(pkg$name, user), - use_badge_codecov(pkg$name, user, domain ), - use_badge_lifecycle(stage), - use_badge_cran(pkg$name), - use_badge_runiverse(pkg$name), - "", - pkg$desc, - "", - use_installation(pkg$name, user, domain) + content <- get_markdown_for_index_or_readme( + is_readme = FALSE, + user = user, + domain = domain, + stage = stage ) - writeLines(index_md, "index.md") - + writeLines(content, "index.md") write_to_rbuildignore(ignore_pattern = "^index\\.md$") - index_md + content } diff --git a/R/use_pkg_skeleton.R b/R/use_pkg_skeleton.R index a72072f..7f6a84e 100644 --- a/R/use_pkg_skeleton.R +++ b/R/use_pkg_skeleton.R @@ -27,9 +27,13 @@ use_pkg_skeleton <- function(pkg_name) usethis::use_git_ignore(".Rproj.user") - if (getFromNamespace("is_package", "usethis")()) { + if (get_from_namespace("is_package", "usethis")()) { usethis::use_build_ignore(c( - rproj_file, ".Rhistory", ".RData", ".Rproj.user" , ".here" + rproj_file, + ".Rhistory", + ".RData", + ".Rproj.user" , + ".here" )) } diff --git a/R/use_readme_md.R b/R/use_readme_md.R index d3d4f15..588c466 100644 --- a/R/use_readme_md.R +++ b/R/use_readme_md.R @@ -13,41 +13,18 @@ #' @importFrom desc desc use_readme_md <- function( - user = "KWB-R", - domain = "github", - stage = "experimental" + user = "KWB-R", + domain = "github", + stage = "experimental" ) { - pkg <- read_description() - - docu_release <- sprintf( - "https://%s.%s.io/%s", - tolower(user), tolower(domain), tolower(pkg$name) + content <- get_markdown_for_index_or_readme( + is_readme = TRUE, + user = user, + domain = domain, + stage = stage ) - docu_dev <- sprintf("%s/dev", docu_release) - - readme_md <- c( - use_badge_ghactions(pkg$name, user), - use_badge_codecov(pkg$name, user, domain ), - use_badge_lifecycle(stage), - use_badge_cran(pkg$name), - use_badge_runiverse(pkg$name), - "", - sprintf("# %s", pkg$name), - "", - pkg$desc, - "", - use_installation(pkg$name, user, domain), - "", - "## Documentation", - "", - sprintf("Release: [%s](%s)", docu_release, docu_release), - "", - sprintf("Development: [%s](%s)", docu_dev, docu_dev) - ) - - writeLines(readme_md, "README.md") - + writeLines(content, "README.md") write_to_rbuildignore(ignore_pattern = "^README\\.md$") }