Skip to content

Commit

Permalink
format output
Browse files Browse the repository at this point in the history
maxheld83 committed Nov 4, 2024

Verified

This commit was signed with the committer’s verified signature.
mxinden Max Inden
1 parent a21431a commit df11243
Showing 6 changed files with 70 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
docs/
man/*.Rd
!man/figures/
man/figures/niffler_screenshots
~*.xlsx
~*.xlsm
# {shinytest2}: Ignore new debug snapshots for `$expect_values()`
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Generated by roxygen2: do not edit by hand

S3method(format,rd_section_nifflerInsertSnaps)
S3method(roxygen2::roxy_tag_parse,roxy_tag_nifflerExamplesShiny)
S3method(roxygen2::roxy_tag_parse,roxy_tag_nifflerInsertSnaps)
S3method(roxygen2::roxy_tag_rd,roxy_tag_nifflerExamplesShiny)
S3method(roxygen2::roxy_tag_rd,roxy_tag_nifflerInsertSnaps)
export(abort_if_not_reactive)
export(abort_if_reactive)
export(counter_button_app)
47 changes: 42 additions & 5 deletions R/shiny2screenshot.R
Original file line number Diff line number Diff line change
@@ -154,19 +154,56 @@ get_screenshot_from_app_strictly <- function(appDir,

#' @rdname tag_shiny
#' @details
#' - `@nifflerInsertSnaps ${1:test_file} ${2:name} ${3:auto_numbered}`
#' - `@nifflerInsertSnaps ${1:test_file} ${2:name} ${3:auto_numbered} ${4:variant} ${5:fps}`

Check warning on line 157 in R/shiny2screenshot.R

GitHub Actions / Test, Check, Lint and Document Package (rlint)

file=R/shiny2screenshot.R,line=157,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 92 characters.
#' Insert screenshots from
#' [shinytest2](https://rstudio.github.io/shinytest2/) snapshots.
#' For arguments and defaults, see [snaps2man()].
#' @usage
#' # @nifflerInsertSnaps ${1:test_file} ${2:name} ${3:auto_numbered}
#' # @nifflerInsertSnaps
#' # ${1:test_file}
#' # ${2:name}
#' # ${3:auto_numbered}
#' # ${4:variant}
#' # ${5:fps}
#' @nifflerInsertSnaps
#' helpers
#' bins
#' FALSE
#' linux
#' @name nifflerInsertSnaps
NULL

#' @exportS3Method roxygen2::roxy_tag_parse
roxy_tag_parse.roxy_tag_nifflerInsertSnaps <- function(x) {
check_installed_roxygen2()
roxygen2::tag_words(x, min = 1, max = 3)
roxygen2::tag_words(x, min = 1, max = 5)
}

#' @exportS3Method roxygen2::roxy_tag_rd
roxy_tag_rd.roxy_tag_nifflerInsertSnaps <- function(x, base_path, env) {
args <- as.list(x[["val"]])
if (length(args) >= 2) args[[3]] <- as.logical(args[[3]])
path <- rlang::exec(snaps2man, !!!args)
roxygen2::rd_section(
type = "nifflerInsertSnaps",
value = path
)
}

#' @export
format.rd_section_nifflerInsertSnaps <- function(x, ...) {
paste0(
"\\section{Screenshots from Tests}{\n",
"\\if{html}",
paste0(
"{\\figure{",
x$value,
"}{options: width='100\\%' alt='Screenshot from App'}}",
collapse = ""
),
"\\if{latex}{Screenshots cannot be shown in this output format.}",
"}\n"
)
}

#' Get shinytest screenshots
@@ -294,7 +331,7 @@ glue_regexp_screenshot_files <- function(name = NULL, auto_numbered = TRUE) {
#' Vector of file names, as returned by [dir_ls_snaps()]
#' @inheritParams magick::image_animate
#' @inheritDotParams magick::image_animate
#' @return A `magick-image`.
#' @return For [image_animate_snaps()] A `magick-image`.
#' @export
image_animate_snaps <- function(snaps = fs::path(), fps = 5, ...) {
if (any(!fs::file_exists(snaps))) rlang::abort("File could not be found.")
@@ -312,7 +349,7 @@ image_animate_snaps <- function(snaps = fs::path(), fps = 5, ...) {
#' @describeIn get_shinytest_screenshots
#' Write out (merged) screenshots to new path.
#' @inheritParams magick::image_write
#' @return Path to the (merged) screenshots.
#' @return For [image_write_snaps()], path to the (merged) screenshots.
#' @export
image_write_snaps <- function(image, path = withr::local_tempfile()) {
magick::image_write(image = image, path = path)
6 changes: 5 additions & 1 deletion inst/examples/snaps2man/example.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#' An example documentation with inserted snaps
#' @nifflerInsertSnaps helpers bins FALSE
#' @nifflerInsertSnaps
#' helpers
#' bins
#' FALSE
#' linux
bins_app <- function() examples_app()
17 changes: 13 additions & 4 deletions tests/testthat/_snaps/shiny2screenshot.md
Original file line number Diff line number Diff line change
@@ -46,15 +46,24 @@
[<text>: 1] @title 'An example documentation with inserted snaps' {parsed}
[[2]]
[<text>: 2] @nifflerInsertSnaps 'helpers bins FALSE' {parsed}
[<text>: 2] @nifflerInsertSnaps '...' {parsed}
[[3]]
[<text>: 3] @usage '<generated>' {parsed}
[<text>: 7] @usage '<generated>' {parsed}
[[4]]
[<text>: 3] @.formals '<generated>' {unparsed}
[<text>: 7] @.formals '<generated>' {unparsed}
[[5]]
[<text>: 3] @backref '<generated>' {parsed}
[<text>: 7] @backref '<generated>' {parsed}

# roxy_tag_nifflerInsertSnaps: can be formatted

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

7 changes: 7 additions & 0 deletions tests/testthat/test-shiny2screenshot.R
Original file line number Diff line number Diff line change
@@ -79,6 +79,13 @@ describe("roxy_tag_nifflerInsertSnaps", {
"can be parsed",
expect_snapshot(roxygen2::parse_text(example)[[1]]$tags)
)
it(
"can be formatted",
{
topic <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), example)[[1]]
expect_snapshot(topic$get_section("nifflerInsertSnaps"))
}
)
})

describe("dir_ls_snaps", {

0 comments on commit df11243

Please sign in to comment.