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

Implement #1008 #1009

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(add_js_input_binding)
export(add_js_output_binding)
export(add_module)
export(add_partial_html_template)
export(add_r6)
export(add_resource_path)
export(add_rstudioconnect_file)
export(add_sass_file)
Expand Down
38 changes: 35 additions & 3 deletions R/add_r_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ add_utils <- function(
)
}

#' @rdname file_creation
#' @export
add_r6 <- function(
name,
module = NULL,
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE
) {
add_r_files(
name,
module,
ext = "class",
pkg = pkg,
open = open,
dir_create = dir_create,
with_test = with_test
)
}
#' Append roxygen comments to `fct_` and `utils_` files
#'
#' This function add boilerplate roxygen comments
Expand All @@ -164,16 +184,21 @@ append_roxygen_comment <- function(

if (ext == "utils") {
file_type <- "utility"
} else {
} else if (ext == "fct") {
file_type <- "function"
} else {
ext <- paste(ext, "generator")
file_type <- "R6"
}

write_there(sprintf("#' %s ", name))
write_there("#'")
write_there(sprintf("#' @description A %s function", ext))
write_there("#'")
write_there(sprintf("#' @return The return value, if any, from executing the %s.", file_type))
write_there("#'")
if (!(file_type == "R6")) {
write_there(sprintf("#' @return The return value, if any, from executing the %s.", file_type))
write_there("#'")
}
if (export) {
write_there("#' @export")
} else {
Expand All @@ -183,4 +208,11 @@ append_roxygen_comment <- function(
write_there(paste(name, "<- function() {"))
write_there("}")
}
if (file_type == "R6") {
write_there(paste0(name, " <- R6::R6Class("))
write_there(paste0(" classname = '", name, "',"))
write_there(" public = list(")
write_there(" )")
write_there(")")
}
}
6 changes: 6 additions & 0 deletions R/modules_fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @param dir_create Creates the directory if it doesn't exist, default is `TRUE`.
#' @param fct If specified, creates a `mod_fct` file.
#' @param utils If specified, creates a `mod_utils` file.
#' @param r6 If specified, creates a `mod_class` file.
#' @param js,js_handler If specified, creates a module related JavaScript file.
#' @param export Should the module be exported? Default is `FALSE`.
#' @param module_template Function that serves as a module template.
Expand All @@ -31,6 +32,7 @@ add_module <- function(
dir_create = TRUE,
fct = NULL,
utils = NULL,
r6 = NULL,
js = NULL,
js_handler = NULL,
export = FALSE,
Expand Down Expand Up @@ -125,6 +127,10 @@ add_module <- function(
)
}

if (!is.null(r6)) {
add_r6(r6, module = name, open = open)
}

if (with_test) {
use_module_test(
name = name,
Expand Down
3 changes: 3 additions & 0 deletions man/add_module.Rd

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

10 changes: 10 additions & 0 deletions man/file_creation.Rd

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