Skip to content

Commit

Permalink
Merge pull request #61 from LukasWallrich/main
Browse files Browse the repository at this point in the history
Change to webshot2
  • Loading branch information
nucleic-acid committed Dec 30, 2022
2 parents 3d80bf7 + e902402 commit 5a74fa3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Imports:
R.utils,
readr,
stringr,
webshot
webshot2
Suggests:
knitr,
rcrossref (>= 1.2),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_trunc)
importFrom(webshot,webshot)
importFrom(webshot2,webshot)
9 changes: 5 additions & 4 deletions R/drop_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#' In other words, either one, many or no BibTeX citation keys can be specified.
#' @param export_as A string specifying the desired output format. For now supports PNG and HTML.
#' Use "html" to include the 'bare' taglist (recommended for inclusion in Rmarkdown documents) or "html_full" to write a standalone .html file including <head> etc.
#' The PNG is a screenshot of the rendered HTML via the 'webshot' package. The filename represents this two step approach on purpose.
#' For webshot you need to install phantomJS once (see 'webshot' documentation).
#' The PNG is a screenshot of the rendered HTML via the 'webshot2' package. The filename represents this two step approach on purpose.
#' @param output_dir A string specifying the relative path, where the rendered output files should be stored.
#' @param max_authors Integer number of maximum authors to print. If the number of authors exceeds this, the list is cropped accordingly.
#' @param include_qr Character string specifying the way the QR code should be included or if no QR code should be included.
Expand Down Expand Up @@ -83,7 +82,7 @@
#' @import dplyr
#' @importFrom htmltools tags save_html
#' @importFrom lubridate year ymd
#' @importFrom webshot webshot
#' @importFrom webshot2 webshot
#' @importFrom stringr str_detect str_remove_all str_trunc str_replace_all

drop_name <- function(bib, cite_key,
Expand Down Expand Up @@ -293,7 +292,9 @@ drop_name <- function(bib, cite_key,
# handle different input options for bibtex keys
if (missing(cite_key)) {
n_bib <- nrow(clean_bib)
message(paste0("No cite_key specified. Working through all possible ", n_bib, " entries in the bibliography."))
if (n_bib > 1) {
message(paste0("No cite_key specified. Working through all possible ", n_bib, " entries in the bibliography."))
}
work_list <- clean_bib
} else if (!is.character(cite_key)) {
stop("cite_key must be of type 'caracter'.")
Expand Down
13 changes: 5 additions & 8 deletions R/write_vc.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' }
#'
#' @importFrom htmltools tags save_html
#' @importFrom webshot webshot
#' @importFrom webshot2 webshot

write_vc <- function(work_item, path_absolute, output_dir, export_as) {

Expand Down Expand Up @@ -73,10 +73,7 @@ write_vc <- function(work_item, path_absolute, output_dir, export_as) {
}
)
} else if (export_as == "png") {
if (!webshot::is_phantomjs_installed()) {
message("You need to download and install phantomJS to save output as PNG. Try running 'webshot::install_phantomjs()' once.")
} else {
# renders as "complete" html to get the white background for PNG snapshot.
# renders as "complete" html to get the white background for PNG snapshot.
tryCatch(
expr = {
htmltools::save_html(work_item$vcs, file = output_file)
Expand All @@ -91,10 +88,9 @@ write_vc <- function(work_item, path_absolute, output_dir, export_as) {
}
)


tryCatch(
expr = {
webshot::webshot(output_file, paste0(output_file, ".png"), selector = ".visual-citation", zoom = 2)
webshot2::webshot(output_file, paste0(output_file, ".png"), selector = ".visual-citation", zoom = 2)
},
error = function(e) {
message("Could not take a screenshot of the intermediate HTML.")
Expand All @@ -116,7 +112,7 @@ write_vc <- function(work_item, path_absolute, output_dir, export_as) {
R.utils::getRelativePath(png_out)
)
return(return_path_png)
}

} else {
stop("Output format unknown")
}
Expand All @@ -128,4 +124,5 @@ write_vc <- function(work_item, path_absolute, output_dir, export_as) {
)

return(return_path_html)

}
3 changes: 1 addition & 2 deletions man/drop_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/drop_name_crossref.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-write_vc.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ test_that("saving as html works as expected", {
# "Some 2023", "Alice; Bob; Charlie", "Journal of Unnecessary R Packages", "Alice2023", "2023", VCS
# )
#
# # writes a file, this test can only be run, if phantomJS is installed:
# if(webshot::is_phantomjs_installed()) {
# # writes a file, this test can only be run, if a chromium browser is installed:
# if(!is.null(chromote::find_chrome())) {
# withr::with_dir(
# new = new,
# code = {
Expand Down

0 comments on commit 5a74fa3

Please sign in to comment.