Skip to content

Commit

Permalink
Merge pull request #58 from jhelvy/pingfan-ui-design
Browse files Browse the repository at this point in the history
Pingfan UI design
pingfan-hu authored Aug 5, 2024
2 parents 5cf8743 + bdbdd9b commit e21a6d5
Showing 4 changed files with 42 additions and 172 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
- (extension) Default page background is set as "#f2f6f9" (a light blue color). Can be overwritten in the YAML header with the `backgroundcolor`.
- (extension) Questions are now encapsulated in a container that distinguishes from the descriptive texts.
- (extension) Options of `mc_button` and `mu_multiple_buttons` types of questions are now centered.
- Now the `surveydown::create_survey()` function will download the whole [extension repo](https://github.com/jhelvy/surveydown-ext/tree/main), containing the extension, an example survey, and an RStudio project.


# surveydown 0.0.3
69 changes: 41 additions & 28 deletions R/templates.R
Original file line number Diff line number Diff line change
@@ -18,38 +18,51 @@
#' create_survey()
#' create_survey(path = "path/to/package", template = "simple")
#' }
create_survey <- function(path = getwd(), template = "simple") {

# Use the usethis ui_ask_yes_no function for confirmation
if (path == getwd()) {
if (
!usethis::ui_yeah(paste(
"Do you want to use the current working directory (",
path, ") as the path?"
))
) {
stop("Operation aborted by the user.")
create_survey <- function(path = getwd()) {
# Use the usethis ui_ask_yes_no function for confirmation
if (path == getwd()) {
if (
!usethis::ui_yeah(paste(
"Do you want to use the current working directory (",
path, ") as the path?"
))
) {
stop("Operation aborted by the user.")
}
}
}

# Ensure the path is valid and create the directory
if (!dir.exists(path)) {
dir.create(path, recursive = TRUE)
}
# Define the URL for the GitHub repository
repo_url <- "https://github.com/jhelvy/surveydown-ext/archive/refs/heads/main.zip"

# Define the source directory within surveydown package
source_dir <- system.file(
file.path("example", template),
package = "surveydown"
)
# Create a temporary file to store the downloaded zip
temp_file <- tempfile(fileext = ".zip")

# Check if the source directory exists
if (source_dir == "") {
stop("Source directory not found in the package for the specified template.")
}
# Download the zip file
utils::download.file(repo_url, temp_file, mode = "wb")

# Copy files and directories recursively from the source to the target path
file.copy(list.files(source_dir, full.names = TRUE), path, recursive = TRUE)
# Create a temporary directory to unzip the contents
temp_dir <- tempfile()
dir.create(temp_dir)

usethis::ui_done(paste("Survey template created at", path))
# Unzip the file
utils::unzip(temp_file, exdir = temp_dir)

# Get the path of the unzipped "surveydown-ext-main" directory
unzipped_dir <- file.path(temp_dir, "surveydown-ext-main")

# Ensure the target path exists
dir.create(path, recursive = TRUE, showWarnings = FALSE)

# Get list of files to move, excluding "." and ".."
files_to_move <- list.files(unzipped_dir, all.files = TRUE, full.names = TRUE, no.. = TRUE)

# Move all contents from unzipped_dir to the target path
file.rename(files_to_move,
file.path(path, basename(files_to_move)))

# Clean up temporary files
unlink(temp_file)
unlink(temp_dir, recursive = TRUE)

usethis::ui_done(paste("Survey template created at", path))
}
22 changes: 0 additions & 22 deletions inst/example/simple/survey.Rproj

This file was deleted.

122 changes: 0 additions & 122 deletions inst/example/simple/survey.qmd

This file was deleted.

0 comments on commit e21a6d5

Please sign in to comment.