Skip to content

Commit

Permalink
Merge branch 'glue-ify'
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Nov 29, 2024
2 parents 68b4b23 + 601d4df commit fe641a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
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)

0 comments on commit fe641a8

Please sign in to comment.