Skip to content

Commit

Permalink
Update conditions, adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toph-allen committed Jun 15, 2022
1 parent 6b1e2aa commit 7080f6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
40 changes: 19 additions & 21 deletions R/bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,27 +413,27 @@ inferAppMode <- function(appDir, appPrimaryDoc, files, quartoInfo) {
# Determine if we have qmd files, and if they use the Shiny runtime
qmdFiles <- grep("^[^/\\\\]+\\.qmd$", files, ignore.case = TRUE, perl = TRUE, value = TRUE)
shinyQmdFiles <- sapply(file.path(appDir, qmdFiles), isShinyRmd)
hasQuartoYaml <- any(grepl("^_quarto.y(a)?ml$", x = files, ignore.case = TRUE, perl = TRUE))

# Trying to deploy Quarto and R Markdown files simultaneously is an error.
if (length(rmdFiles) > 0 && length(qmdFiles) > 0) {
stop("Cannot infer app mode because there are both .qmd and .Rmd files in deployment files.")
}
requiresQuarto <- any(length(qmdFiles > 0), hasQuartoYaml)

# To deploy Quarto content, we need to have received or inferred Quarto metadata.
missingQuartoInfoErrorText <- paste(
"Attempting to deploy Quarto project without Quarto metadata.",
"Please provide the path to a quarto binary to the 'quarto' argument."
)
# We gate the deployment of content that appears to be Quarto behind the
# presence of Quarto metadata. Rmd files can still be deployed as Quarto
# content.
if (requiresQuarto && is.null(quartoInfo)) {
stop(paste(
"Attempting to deploy Quarto content without Quarto metadata.",
"Please provide the path to a quarto binary to the 'quarto' argument."
))
}

# Shiny or Quarto documents with "server: shiny" in their YAML front matter
# are rmd-shiny or quarto-shiny.
if (any(shinyRmdFiles)) {
return("rmd-shiny")
} else if (any(shinyQmdFiles)) {
if (is.null(quartoInfo)) {
stop(missingQuartoInfoErrorText)
} else {
if (any(shinyRmdFiles) || any(shinyQmdFiles)) {
if (!is.null(quartoInfo)) {
return("quarto-shiny")
} else {
return("rmd-shiny")
}
}

Expand All @@ -447,13 +447,11 @@ inferAppMode <- function(appDir, appPrimaryDoc, files, quartoInfo) {

# Any non-Shiny R Markdown or Quarto documents are rendered content and get
# rmd-static or quarto-static.
if (length(rmdFiles) > 0) {
return("rmd-static")
} else if (length(qmdFiles) > 0) {
if (is.null(quartoInfo)) {
stop(missingQuartoInfoErrorText)
} else {
if (length(rmdFiles) > 0 || length(qmdFiles) > 0) {
if (!is.null(quartoInfo)) {
return("quarto-static")
} else {
return("rmd-static")
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ test_that("writeManifest: Quarto Python-only website gets correct manifest data"

test_that("writeManifest: Deploying Quarto content without Quarto info in an error", {
missingQuartoInfoErrorText <- paste(
"Attempting to deploy Quarto project without Quarto metadata.",
"Attempting to deploy Quarto content without Quarto metadata.",
"Please provide the path to a quarto binary to the 'quarto' argument."
)

Expand All @@ -576,14 +576,14 @@ test_that("writeManifest: Deploying Quarto content without Quarto info in an err
)
})

test_that("writeManifest: Attempting to deploy a directory with Rmd and qmd files is an error", {
test_that("writeManifest: Deploying R Markdown content with Quarto gives a Quarto app mode", {
quarto <- quartoPathOrSkip()

appDir <- "qmd-and-rmd"
expect_error(
makeManifest(appDir, appPrimaryDoc = NULL, quarto = quarto),
"Cannot infer app mode because there are both .qmd and .Rmd files in deployment files."
)
manifest <- makeManifest("test-rmds", "simple.Rmd", quarto = quarto)

expect_equal(manifest$metadata$appmode, "quarto-static")
expect_equal(manifest$quarto$engines, "knitr")
expect_equal(manifest$metadata$primary_rmd, "simple.Rmd")
})

test_that("writeManifest: Sets environment.image in the manifest if one is provided", {
Expand Down

0 comments on commit 7080f6f

Please sign in to comment.