Skip to content

Commit fe641a8

Browse files
committed
Merge branch 'glue-ify'
2 parents 68b4b23 + 601d4df commit fe641a8

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

R/shiny2screenshot.R

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,24 @@ roxy_tag_rd.roxy_tag_crowInsertSnaps <- function(x, base_path, env) {
210210
)
211211
}
212212

213+
glue_latex <- function(..., .envir = parent.frame()) {
214+
glue::glue(..., .envir = .envir, .open = "[", .close = "]")
215+
}
216+
213217
#' @export
214218
format.rd_section_crowInsertSnaps <- function(x, ...) {
215-
paste0(
216-
"\\section{Screenshots from Tests}{\n",
217-
"\\if{html}",
218-
paste(x$value, collapse = "\n"),
219-
"\\if{latex}{Screenshots cannot be shown in this output format.}",
220-
"}\n"
219+
inner <- glue::glue_collapse(x$value, sep = "\n")
220+
# appease check
221+
inner
222+
glue_latex(
223+
"\\section{Screenshots from Tests}{
224+
\\if{html}{
225+
[inner]
226+
}
227+
\\if{latex}{
228+
Screenshots cannot be shown in this output format.
229+
}
230+
}"
221231
)
222232
}
223233

@@ -279,7 +289,7 @@ snap_alt_text <- function() "Screenshot from App"
279289
#' @export
280290
snaps2md <- function(...) {
281291
path <- snaps2fig(...)
282-
paste0("![", snap_alt_text(), "](", path, ")", collapse = "")
292+
glue::glue("![{snap_alt_text()}]({path})")
283293
}
284294

285295
#' @describeIn get_screenshot_from_snaps
@@ -300,19 +310,11 @@ snaps2rd <- function(test_file = character(),
300310
variant = variant,
301311
fps = fps
302312
)
303-
glue::glue_collapse(
304-
c(
305-
glue::glue("{{name: \\code{{{name}}}, variant: \\code{{{variant}}}"),
306-
paste0(
307-
"\\figure{",
308-
path,
309-
"}{options: width='100\\%' alt=",
310-
snap_alt_text(),
311-
"}}",
312-
collapse = ""
313-
)
314-
),
315-
sep = " "
313+
# appease make check
314+
path
315+
glue_latex(
316+
"name: \\code{[name]}, variant: \\code{[variant]}
317+
\\figure{[path]}{options: width='100\\%' alt=[snap_alt_text()]}"
316318
)
317319
}
318320

tests/testthat/_snaps/shiny2screenshot.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,36 @@
6464
topic$get_section("crowInsertSnaps")
6565
Output
6666
\section{Screenshots from Tests}{
67-
\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.}}
68-
67+
\if{html}{
68+
name: \code{bins}, variant: \code{linux}
69+
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
70+
}
71+
\if{latex}{
72+
Screenshots cannot be shown in this output format.
73+
}
74+
}
6975

7076
# roxy_tag_crowInsertSnaps: can be formatted with multiple tags joined
7177

7278
Code
7379
topic$get_section("crowInsertSnaps")
7480
Output
7581
\section{Screenshots from Tests}{
76-
\if{html}{name: \code{bins}, variant: \code{linux} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}
77-
{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.}}
78-
82+
\if{html}{
83+
name: \code{bins}, variant: \code{linux}
84+
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
85+
name: \code{bins}, variant: \code{mac}
86+
\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}
87+
}
88+
\if{latex}{
89+
Screenshots cannot be shown in this output format.
90+
}
91+
}
7992

8093
# snaps2fig and friends work: writes out markdown syntax
8194

8295
Code
8396
res
8497
Output
85-
[1] "![Screenshot from App](crow_screenshots/helpers/bins.gif)"
98+
![Screenshot from App](crow_screenshots/helpers/bins.gif)
8699

0 commit comments

Comments
 (0)