Skip to content
Merged
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
42 changes: 22 additions & 20 deletions R/shiny2screenshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,24 @@ roxy_tag_rd.roxy_tag_crowInsertSnaps <- function(x, base_path, env) {
)
}

glue_latex <- function(..., .envir = parent.frame()) {
glue::glue(..., .envir = .envir, .open = "[", .close = "]")
}

#' @export
format.rd_section_crowInsertSnaps <- function(x, ...) {
paste0(
"\\section{Screenshots from Tests}{\n",
"\\if{html}",
paste(x$value, collapse = "\n"),
"\\if{latex}{Screenshots cannot be shown in this output format.}",
"}\n"
inner <- glue::glue_collapse(x$value, sep = "\n")
# appease check
inner
glue_latex(
"\\section{Screenshots from Tests}{
\\if{html}{
[inner]
}
\\if{latex}{
Screenshots cannot be shown in this output format.
}
}"
)
}

Expand Down Expand Up @@ -279,7 +289,7 @@ snap_alt_text <- function() "Screenshot from App"
#' @export
snaps2md <- function(...) {
path <- snaps2fig(...)
paste0("![", snap_alt_text(), "](", path, ")", collapse = "")
glue::glue("![{snap_alt_text()}]({path})")
}

#' @describeIn get_screenshot_from_snaps
Expand All @@ -300,19 +310,11 @@ snaps2rd <- function(test_file = character(),
variant = variant,
fps = fps
)
glue::glue_collapse(
c(
glue::glue("{{name: \\code{{{name}}}, variant: \\code{{{variant}}}"),
paste0(
"\\figure{",
path,
"}{options: width='100\\%' alt=",
snap_alt_text(),
"}}",
collapse = ""
)
),
sep = " "
# appease make check
path
glue_latex(
"name: \\code{[name]}, variant: \\code{[variant]}
\\figure{[path]}{options: width='100\\%' alt=[snap_alt_text()]}"
)
}

Expand Down
25 changes: 19 additions & 6 deletions tests/testthat/_snaps/shiny2screenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,36 @@
topic$get_section("crowInsertSnaps")
Output
\section{Screenshots from Tests}{
\if{html}{name: \code{bins}, variant: \code{linux} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}

\if{html}{
name: \code{bins}, variant: \code{linux}
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
}
\if{latex}{
Screenshots cannot be shown in this output format.
}
}

# roxy_tag_crowInsertSnaps: can be formatted with multiple tags joined

Code
topic$get_section("crowInsertSnaps")
Output
\section{Screenshots from Tests}{
\if{html}{name: \code{bins}, variant: \code{linux} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}
{name: \code{bins}, variant: \code{mac} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}

\if{html}{
name: \code{bins}, variant: \code{linux}
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
name: \code{bins}, variant: \code{mac}
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
}
\if{latex}{
Screenshots cannot be shown in this output format.
}
}

# snaps2fig and friends work: writes out markdown syntax

Code
res
Output
[1] "![Screenshot from App](crow_screenshots/helpers/bins.gif)"
![Screenshot from App](crow_screenshots/helpers/bins.gif)