-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from mcanouil/feat-new-commands
Co-authored-by: Christophe Dervieux <[email protected]>
- Loading branch information
Showing
17 changed files
with
273 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: quarto | ||
Title: R Interface to 'Quarto' Markdown Publishing System | ||
Version: 1.3.3 | ||
Version: 1.3.4 | ||
Authors@R: c( | ||
person("JJ", "Allaire", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-0174-9868")), | ||
|
@@ -14,9 +14,11 @@ URL: https://github.com/quarto-dev/quarto-r, | |
https://quarto-dev.github.io/quarto-r/ | ||
BugReports: https://github.com/quarto-dev/quarto-r/issues | ||
Imports: | ||
cli, | ||
jsonlite, | ||
later, | ||
processx, | ||
rlang, | ||
rmarkdown, | ||
rsconnect (>= 0.8.26), | ||
rstudioapi, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#' Internal package state | ||
#' @noRd | ||
quarto <- new.env(parent = emptyenv()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' Install a Quarto extensions | ||
#' | ||
#' Add an extension to this folder or project by running `quarto add` | ||
#' | ||
#' # Extension Trust | ||
#' | ||
#' Quarto extensions may execute code when documents are rendered. Therefore, if | ||
#' you do not trust the author of an extension, we recommend that you do not | ||
#' install or use the extension. | ||
#' By default `no_prompt = FALSE` which means that | ||
#' the function will ask for explicit approval when used interactively, or | ||
#' disallow installation. | ||
#' | ||
#' @param extension The extension to install, either an archive or a GitHub | ||
#' repository as described in the documentation | ||
#' <https://quarto.org/docs/extensions/managing.html>. | ||
#' | ||
#' @param no_prompt Do not prompt to confirm approval to download external extension. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Install a template and set up a draft document from a GitHub repository | ||
#' quarto_add_extension("quarto-ext/fontawesome") | ||
#' | ||
#' # Install a template and set up a draft document from a ZIP archive | ||
#' quarto_add_extension("https://github.com/quarto-ext/fontawesome/archive/refs/heads/main.zip") | ||
#' } | ||
#' | ||
#' @importFrom rlang is_interactive | ||
#' @importFrom cli cli_abort | ||
#' @export | ||
quarto_add_extension <- function(extension = NULL, no_prompt = FALSE) { | ||
rlang::check_required(extension) | ||
|
||
quarto_bin <- find_quarto() | ||
|
||
# This will ask for approval or stop installation | ||
check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html") | ||
|
||
args <- c(extension,"--no-prompt") | ||
|
||
quarto_add(args, quarto_bin = quarto_bin, echo = TRUE) | ||
|
||
invisible() | ||
} | ||
|
||
quarto_add <- function(args = character(), ...) { | ||
quarto_run_what("add", args = args, ...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
#' Internal package state | ||
#' @noRd | ||
quarto <- new.env(parent = emptyenv()) | ||
## usethis namespace: start | ||
#' @import rlang | ||
#' @importFrom cli cli_inform | ||
## usethis namespace: end | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Use a custom format extension template | ||
#' | ||
#' Install and use a template for Quarto using `quarto use`. | ||
#' | ||
#' @inheritParams quarto_add_extension | ||
#' | ||
#' @param template The template to install, either an archive or a GitHub | ||
#' repository as described in the documentation | ||
#' <https://quarto.org/docs/extensions/formats.html>. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Install a template and set up a draft document from a GitHub repository | ||
#' quarto_use_template("quarto-journals/jss") | ||
#' | ||
#' # Install a template and set up a draft document from a ZIP archive | ||
#' quarto_use_template("https://github.com/quarto-journals/jss/archive/refs/heads/main.zip") | ||
#' } | ||
#' | ||
#' @export | ||
quarto_use_template <- function(template, no_prompt = FALSE) { | ||
rlang::check_required(template) | ||
|
||
quarto_bin <- find_quarto() | ||
|
||
# This will ask for approval or stop installation | ||
check_extension_approval(no_prompt, "Quarto templates", "https://quarto.org/docs/extensions/formats.html#distributing-formats") | ||
|
||
args <- c("template", template, "--no-prompt") | ||
|
||
quarto_use(args, quarto_bin = quarto_bin, echo = TRUE) | ||
|
||
invisible() | ||
} | ||
|
||
quarto_use <- function(args = character(), ...) { | ||
quarto_run_what("use", args = args, ...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
check_extension_approval <- function(no_prompt = FALSE, what = "Something", see_more_at = NULL) { | ||
if (!no_prompt) { | ||
if (!rlang::is_interactive()) { | ||
cli::cli_abort(c( | ||
"{ what } requires explicit approval.", | ||
'>' = "Set {.arg no_prompt = TRUE} if you agree.", | ||
if (!is.null(see_more_at)) { | ||
c(i = "See more at {.url {see_more_at}}") | ||
} | ||
)) | ||
} else { | ||
cli::cli_inform(c( | ||
"{what} may execute code when documents are rendered. ", | ||
'*' = "If you do not trust the author(s) of this {what}, we recommend that you do not install or use this {what}." | ||
)) | ||
prompt_value <- tolower(readline(sprintf("Do you trust the authors of this %s (Y/n)? ", what))) | ||
if (!prompt_value %in% "y") { | ||
cli::cli_inform("{what} not installed.") | ||
return(invisible(FALSE)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test_that("Installing an extension", { | ||
skip_if_no_quarto() | ||
skip_if_offline("github.com") | ||
qmd <- local_qmd_file(c("content")) | ||
withr::local_dir(dirname(qmd)) | ||
expect_error(quarto_add_extension("quarto-ext/fontawesome"), "explicit approval") | ||
quarto_add_extension("quarto-ext/fontawesome", no_prompt = TRUE) | ||
expect_true(dir.exists("_extensions/quarto-ext/fontawesome")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test_that("Installing an extension", { | ||
skip_if_no_quarto() | ||
skip_if_offline("github.com") | ||
dir <- withr::local_tempdir() | ||
withr::local_dir(dir) | ||
expect_error(quarto_use_template("quarto-journals/jss"), "explicit approval") | ||
quarto_use_template("quarto-journals/jss", no_prompt = TRUE) | ||
expect_true(dir.exists("_extensions/quarto-journals/jss")) | ||
expect_length(list.files(pattern = "[.]qmd$"), 1) | ||
}) |