Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #93

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Imports:
openssl,
pkgdown,
processx,
rematch2,
sessioninfo,
usethis,
withr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions R/deploy_site_github_with_extra_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
62 changes: 62 additions & 0 deletions R/get_markdown_for_index_or_readme.R
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion R/use_badges.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions R/use_codecov.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
26 changes: 10 additions & 16 deletions R/use_index_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions R/use_pkg_skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
}

Expand Down
41 changes: 9 additions & 32 deletions R/use_readme_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -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$")
}
Loading