From 09d2dbefa761a4f7fd762c85759875cc7c1639b6 Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 17:24:32 +0100 Subject: [PATCH 1/6] factor out some glue --- R/shiny2screenshot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/shiny2screenshot.R b/R/shiny2screenshot.R index 1e76442..3820e66 100644 --- a/R/shiny2screenshot.R +++ b/R/shiny2screenshot.R @@ -279,7 +279,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 From a0d825131de543d71c3b8dbbf02f533437663d3f Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 17:35:01 +0100 Subject: [PATCH 2/6] fix snap glue has different print method --- tests/testthat/_snaps/shiny2screenshot.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/shiny2screenshot.md b/tests/testthat/_snaps/shiny2screenshot.md index 58841e0..59cd5af 100644 --- a/tests/testthat/_snaps/shiny2screenshot.md +++ b/tests/testthat/_snaps/shiny2screenshot.md @@ -82,5 +82,5 @@ Code res Output - [1] "![Screenshot from App](crow_screenshots/helpers/bins.gif)" + ![Screenshot from App](crow_screenshots/helpers/bins.gif) From 77491a0462a0528e35534ff730026042ccef646b Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 20:58:19 +0100 Subject: [PATCH 3/6] improve indentation --- R/shiny2screenshot.R | 19 +++++++++++++------ tests/testthat/_snaps/shiny2screenshot.md | 22 +++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/R/shiny2screenshot.R b/R/shiny2screenshot.R index 3820e66..ae8c02c 100644 --- a/R/shiny2screenshot.R +++ b/R/shiny2screenshot.R @@ -210,14 +210,21 @@ 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") + glue_latex( + "\\section{Screenshots from Tests} + \\if{html}{ + [inner] + } + \\if{latex}{ + Screenshots cannot be shown in this output format. + }" ) } diff --git a/tests/testthat/_snaps/shiny2screenshot.md b/tests/testthat/_snaps/shiny2screenshot.md index 59cd5af..7b73451 100644 --- a/tests/testthat/_snaps/shiny2screenshot.md +++ b/tests/testthat/_snaps/shiny2screenshot.md @@ -63,19 +63,27 @@ 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}}\if{latex}{Screenshots cannot be shown in this output format.}} - + \section{Screenshots from Tests} + \if{html}{ + name: \code{bins}, variant: \code{linux} + } + \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.}} - + \section{Screenshots from Tests} + \if{html}{ + name: \code{bins}, variant: \code{linux} + name: \code{bins}, variant: \code{mac} + } + \if{latex}{ + Screenshots cannot be shown in this output format. + } # snaps2fig and friends work: writes out markdown syntax From 747163b3b3dca884b66e7cba8c92efdefcab999d Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 21:31:02 +0100 Subject: [PATCH 4/6] fix lint --- R/shiny2screenshot.R | 15 +++++++----- tests/testthat/_snaps/shiny2screenshot.md | 28 ++++++++++++----------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/R/shiny2screenshot.R b/R/shiny2screenshot.R index ae8c02c..806aff6 100644 --- a/R/shiny2screenshot.R +++ b/R/shiny2screenshot.R @@ -217,13 +217,16 @@ glue_latex <- function(..., .envir = parent.frame()) { #' @export format.rd_section_crowInsertSnaps <- function(x, ...) { 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. + "\\section{Screenshots from Tests}{ + \\if{html}{ + [inner] + } + \\if{latex}{ + Screenshots cannot be shown in this output format. + } }" ) } diff --git a/tests/testthat/_snaps/shiny2screenshot.md b/tests/testthat/_snaps/shiny2screenshot.md index 7b73451..ac5cdff 100644 --- a/tests/testthat/_snaps/shiny2screenshot.md +++ b/tests/testthat/_snaps/shiny2screenshot.md @@ -63,12 +63,13 @@ Code topic$get_section("crowInsertSnaps") Output - \section{Screenshots from Tests} - \if{html}{ - name: \code{bins}, variant: \code{linux} - } - \if{latex}{ - Screenshots cannot be shown in this output format. + \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. + } } # roxy_tag_crowInsertSnaps: can be formatted with multiple tags joined @@ -76,13 +77,14 @@ Code topic$get_section("crowInsertSnaps") Output - \section{Screenshots from Tests} - \if{html}{ - name: \code{bins}, variant: \code{linux} - name: \code{bins}, variant: \code{mac} - } - \if{latex}{ - Screenshots cannot be shown in this output format. + \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. + } } # snaps2fig and friends work: writes out markdown syntax From 8d3aa68b9297c53113f160393338f80284855023 Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 21:52:44 +0100 Subject: [PATCH 5/6] refactor tex-writing --- R/shiny2screenshot.R | 16 +++------------- tests/testthat/_snaps/shiny2screenshot.md | 9 ++++++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/R/shiny2screenshot.R b/R/shiny2screenshot.R index 806aff6..d801053 100644 --- a/R/shiny2screenshot.R +++ b/R/shiny2screenshot.R @@ -310,19 +310,9 @@ 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 = " " + glue_latex( + "name: \\code{[name]}, variant: \\code{[variant]} + \\figure{[path]}{options: width='100\\%' alt=[snap_alt_text()]}" ) } diff --git a/tests/testthat/_snaps/shiny2screenshot.md b/tests/testthat/_snaps/shiny2screenshot.md index ac5cdff..9086c48 100644 --- a/tests/testthat/_snaps/shiny2screenshot.md +++ b/tests/testthat/_snaps/shiny2screenshot.md @@ -65,7 +65,8 @@ 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{linux} + \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App} } \if{latex}{ Screenshots cannot be shown in this output format. @@ -79,8 +80,10 @@ 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}} + 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. From 601d4df0f2e24e73f5ae724e05f94f8de5fad80e Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Fri, 29 Nov 2024 21:58:01 +0100 Subject: [PATCH 6/6] fix lint --- R/shiny2screenshot.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/shiny2screenshot.R b/R/shiny2screenshot.R index d801053..82cfd2f 100644 --- a/R/shiny2screenshot.R +++ b/R/shiny2screenshot.R @@ -310,6 +310,8 @@ snaps2rd <- function(test_file = character(), variant = variant, fps = fps ) + # appease make check + path glue_latex( "name: \\code{[name]}, variant: \\code{[variant]} \\figure{[path]}{options: width='100\\%' alt=[snap_alt_text()]}"