R/stimulus-controller.R

Defines functions ss_use_controller

Documented in ss_use_controller

#' @title Create a new Stimulus Controller
#'
#' @description
#' Creates a template at the destination directory with the specific name.
#'
#' @param name (str) stimulus controller name
#' @param dir  (dir) directory to save it in
#'
#' @family Stimulus
#'
#' @export
ss_use_controller <- function(name, dir = ".") {

  assert_string(name)
  assert_directory_exists(dir)

  controller_path <- path(dir, paste0(to_snake_case(name), "_controller.js"))

  file_copy(pkg_inst("templates", "controller.js"), controller_path)

  if (interactive()) file.edit(controller_path) # nocov

  return(controller_path)

}
tjpalanca/hotwire.R documentation built on Dec. 23, 2021, 10:59 a.m.