Skip to content

Commit

Permalink
feat: copy asset files from template_dir
Browse files Browse the repository at this point in the history
Treat `.html` files as templates for interpolation, and copy all other files as-is.
  • Loading branch information
gadenbuie committed Jun 28, 2024
1 parent fc82c6a commit 63bbac2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions R/app_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ write_app_json <- function(

# Then iterate over the HTML files in the template directory and interpolate
# the template parameters.
template_html_files <- fs::dir_ls(html_source_dir, recurse = TRUE, glob = "**.html")
template_html_files <- fs::dir_ls(html_source_dir, recurse = TRUE)

template_params <- rlang::dots_list(
# Forced parameters
Expand All @@ -189,16 +189,18 @@ write_app_json <- function(
)

for (template_file in template_html_files) {
file_content <- brio::read_file(template_file)

file_content_interp <- whisker::whisker.render(
template = file_content,
data = template_params
)

dest_file <- fs::path(app_destdir, fs::path_rel(template_file, html_source_dir))
fs::dir_create(fs::path_dir(dest_file))
brio::write_file(file_content_interp, dest_file)

if (fs::path_ext(template_file) == "html") {
file_content <- whisker::whisker.render(
template = brio::read_file(template_file),
data = template_params
)
brio::write_file(file_content_interp, dest_file)
} else {
fs::file_copy(template_file, dest_file)
}
}

app_json_output_file <- fs::path(app_destdir, "app.json")
Expand Down

0 comments on commit 63bbac2

Please sign in to comment.