Skip to content

Commit

Permalink
Badge improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 11, 2017
1 parent 2316c98 commit 9b55e44
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(create_package)
export(use_apl2_license)
export(use_appveyor)
export(use_badge)
export(use_build_ignore)
export(use_code_of_conduct)
export(use_coverage)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# usethis 0.0.0.9000

* New `use_badge()` for adding any badge to a README. Now only prints a
todo message if the badge does not already exist.

* `use_revdep()` creates structure for use with revdepcheck package, the
preferred way to run revdepchecks. (#33)

Expand Down
27 changes: 23 additions & 4 deletions R/badge.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,31 @@ use_cran_badge <- function(base_path = ".") {
invisible(TRUE)
}

#' Use a README badge
#'
#' @param badge_name Badge name. Used in error message and alt text
#' @param href,src Badge link and image src
#' @inheritParams use_template
#' @export
use_badge <- function(badge_name, href, src, base_path = ".") {
if (has_badge(href, base_path)) {
return(FALSE)
}

img <- paste0("![", badge_name, "](", src, ")")
link <- paste0("[", img, "](", href, ")")

todo(
"Add a ", badge_name, " badge by adding the following line to your README:",
link
)
todo("Add a ", badge_name, " badge by adding the following line to your README:")
code_block(link)
}

has_badge <- function(href, base_path = ".") {
readme_path <- file.path(base_path, "README.md")
if (!file.exists(readme_path)) {
return(FALSE)
}

readme <- readLines(readme_path)
any(grepl(href, readme, fixed = TRUE))

}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Travis build status](https://travis-ci.org/r-lib/usethis.svg?branch=master)](https://travis-ci.org/r-lib/usethis)
[![codecov](https://codecov.io/gh/r-lib/usethis/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis)
[![CRAN status](http://www.r-pkg.org/badges/version/usethis)](https://cran.r-project.org/package=usethis)

The goal of usethis is to automate many common package and analysis setup tasks.

Expand Down
18 changes: 18 additions & 0 deletions man/use_badge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b55e44

Please sign in to comment.