roclet_output.roclet_platen <- function(x, results, base_path, ...) {
## Step 1 - directory control ----------
tmp0 <- results$book_dir
results_dir <- here::here(tmp0, "results", results$fn_name)
if (!dir.exists(results_dir)) dir.create(results_dir)
## Step 2 - edit and customize the Quarto file for this page. Create any additional output needed for the page. ----------
## this step should be modular -- call with a separate function
tmp1 <- readr::read_lines(here::here(tmp0, "template.qmd"))
yaml_end_line <- tmp1 %>%
stringr::str_equal("---") %>%
which() %>%
max()
template_chunks <- create_chunks(results)
zz1 <- here::here(results_dir, "diagram.html")
hide_string <- dplyr::case_when(
is.null(results$hide) ~ "NULL",
TRUE ~ paste0("c('", paste(results$hide, collapse = "','"), "')")
)
zz2 <- paste0(
"flow::flow_view_deps(",
"fun = ", results$fn_name, ", ",
"out = '", zz1, "', ",
"hide = ", hide_string, ")"
)
tryCatch({
eval(parse(text = zz2))
}, error = function (e) {
sink(here::here(results_dir, "error_log.txt"))
message(e)
cat(zz2)
sink()
})
tmp2 <- c(
stringr::str_replace(
tmp1[1:yaml_end_line],
"title: \"\"",
paste0("title: \"", results$fn_name,"()\"")
),
c(
"",
template_chunks$param_import_chunk,
"",
"{{< include ../../diagram_import_chunk.qmd >}}",
"",
template_chunks$fn_print_chunk,
"{{< include ../../custom_chunk1.qmd >}}"
),
tmp1[(yaml_end_line+1):length(tmp1)]
)
## Step 3 - save results and Quarto file ----------
results %>% readr::write_rds(here::here(results_dir, "results.rds"))
tmp2 %>% readr::write_lines(here::here(results_dir, "results.qmd"))
invisible(NULL)
}