Browse Source

addin

master
boB Rudis 6 years ago
parent
commit
ca0798ae57
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 1
      NEWS.md
  4. 1
      R/cloc-package.r
  5. 38
      R/strip-rmd.R
  6. 2
      R/utils.R
  7. 4
      inst/rstudio/addins.dcf

1
DESCRIPTION

@ -14,6 +14,7 @@ Description: Counts blank lines, comment lines, and physical lines of source cod
SystemRequirements: perl
Copyright: file inst/COPYRIGHTS
Imports:
rstudioapi (>= 0.5),
git2r,
utils,
dplyr,

1
NAMESPACE

@ -10,6 +10,7 @@ export(cloc_os)
export(cloc_remove_comments)
export(cloc_reognized_languages)
export(cloc_version)
import(rstudioapi)
importFrom(git2r,clone)
importFrom(processx,run)
importFrom(utils,contrib.url)

1
NEWS.md

@ -10,6 +10,7 @@
- URLs as sources work in more funtions now
- cloc_git() can now clone repo when using git:// URLs
- removed dplyr dependency
- created an RStudio addin to enable reducing the active Rmd document to just code (in a new document)
# cloc 0.1.0

1
R/cloc-package.r

@ -54,6 +54,7 @@
#' @name cloc-package
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import rstudioapi
#' @importFrom git2r clone
#' @importFrom processx run
#' @importFrom utils read.table contrib.url download.file download.packages tail

38
R/strip-rmd.R

@ -0,0 +1,38 @@
#' @keywords internal
strip_rmd <- function() {
ctx <- rstudioapi::getActiveDocumentContext()
if (!is.null(ctx)) {
if (is_rmd_file(ctx$path)) {
x <- basename(ctx$path)
x <- tools::file_path_sans_ext(x)
tf1 <- tempfile(pattern = x, fileext = ".Rmd")
on.exit(unlink(tf1), add = TRUE)
tf2 <- tempfile(pattern = x, fileext = ".R")
cat(ctx$contents, file = tf1, sep = "\n")
nc <- cloc_remove_comments(tf1)
cat(nc, file = tf2)
navigateToFile(tf2, line = -1L, column = -1L)
message(
sprintf(
"Temporary file generated is in [%s]", tf2
)
)
} else {
stop("Can only style .R and .Rmd files.", call. = FALSE)
}
}
}

2
R/utils.R

@ -13,3 +13,5 @@ find_perl <- function() {
return(perl)
}
is_rmd_file <- function(path) { grepl("\\.Rmd$", path, ignore.case = TRUE) }

4
inst/rstudio/addins.dcf

@ -0,0 +1,4 @@
Name: Strip Rmd
Description: Removes everything but code blocks from the active Rmd file
Binding: strip_rmd
Interactive: false
Loading…
Cancel
Save