Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
17 changes: 7 additions & 10 deletions R/golem_hook.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by fusen: do not edit by hand
# WARNING - Generated by {fusen} from /dev/flat_golem_hook.Rmd: do not edit by hand

#' Golem Hook function
#'
Expand All @@ -10,22 +10,19 @@
#' if (requireNamespace("golem") & interactive()) {
#' golem::create_golem("myapp", project_hook = golem_hook)
#' }
golem_hook <- function(
path,
package_name,
...
) {
golem_hook <- function(path, package_name, ...) {
unlink("R/run_app.R", TRUE, TRUE)
unlink("R/app_ui.R", TRUE, TRUE)
unlink("R/app_server.R", TRUE, TRUE)

file.copy(
system.file(
"golem/run_app.R",
package = "brochure"
),
"R/run_app.R"
)

# Include `package_name` as `app_title` in in run_app()
run_app <- readLines(
"R/run_app.R"
)
Expand All @@ -35,15 +32,15 @@ golem_hook <- function(
run_app
)
write(run_app, "R/run_app.R")

file.copy(
system.file(
"golem/mod_home.R",
package = "brochure"
),
"R/mod_home.R"
)

dev_R <- readLines(
"dev/02_dev.R"
)
Expand All @@ -55,7 +52,7 @@ golem_hook <- function(
)
)
] <- 'golem::add_module(name = "name_of_module1", with_test = TRUE, module_template = brochure::new_page) # Name of the module'

dev_R[
which(
grepl(
Expand Down
2 changes: 1 addition & 1 deletion R/new_page.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by fusen: do not edit by hand
# WARNING - Generated by {fusen} from /dev/flat_add_page.Rmd: do not edit by hand

#' Add page
#'
Expand Down
17 changes: 17 additions & 0 deletions brochure.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
31 changes: 23 additions & 8 deletions dev/flat_add_page.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (requireNamespace("golem") & interactive()) {
test_that("golem_hook works", {
x <- tempfile(fileext = ".R")
new_page("pouet", x)

tmplt <- readLines(
x
)
Expand All @@ -71,24 +71,39 @@ test_that("golem_hook works", {
expect_true(
grepl("page", tmplt)
)

skip_if_not_installed("golem")
old <- setwd(tempdir())
on.exit(setwd(old))
unlink("testgolembrochure", TRUE, TRUE)
golem::create_golem("testgolembrochure", project_hook = brochure::golem_hook)
setwd("testgolembrochure")

path_dummy_golem <- tempfile(pattern = "dummygolem")
golem::create_golem(
path = path_dummy_golem,
open = FALSE,
project_hook = brochure::golem_hook
)

old_wd <- setwd(path_dummy_golem)
on.exit({
unlink(path_dummy_golem, TRUE, TRUE)
setwd(old_wd)
})

golem::add_module(name = "pouet", module_template = brochure::new_page)
expect_true(
file.exists("R/mod_pouet.R")
)

})
```


```{r development-inflate, eval=FALSE}
# Run but keep eval=FALSE to avoid infinite loop
# Execute in the console directly
fusen::inflate(flat_file = "dev/flat_add_page.Rmd", vignette_name = NA, document = FALSE)
fusen::inflate(
flat_file = "dev/flat_add_page.Rmd",
vignette_name = NA,
check = FALSE,
document = FALSE
)
```

86 changes: 67 additions & 19 deletions dev/flat_golem_hook.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ golem_hook <- function(path, package_name, ...) {
unlink("R/run_app.R", TRUE, TRUE)
unlink("R/app_ui.R", TRUE, TRUE)
unlink("R/app_server.R", TRUE, TRUE)

file.copy(
system.file(
"golem/run_app.R",
package = "brochure"
),
"R/run_app.R"
)
# Include `package_name` as `app_title` in in run_app()
run_app <- readLines(
"R/run_app.R"
)
run_app <- gsub(
"REPLACEME",
package_name,
run_app
)
write(run_app, "R/run_app.R")

file.copy(
system.file(
"golem/mod_home.R",
package = "brochure"
),
"R/mod_home.R"
)

dev_R <- readLines(
"dev/02_dev.R"
)
Expand All @@ -54,7 +66,7 @@ golem_hook <- function(path, package_name, ...) {
)
)
] <- 'golem::add_module(name = "name_of_module1", with_test = TRUE, module_template = brochure::new_page) # Name of the module'

dev_R[
which(
grepl(
Expand All @@ -76,12 +88,23 @@ if (requireNamespace("golem") & interactive()) {

```{r tests-my_fun}
test_that("golem_hook works", {

skip_if_not_installed("golem")
old <- setwd(tempdir())
on.exit(setwd(old))
unlink("testgolembrochure", TRUE, TRUE)
golem::create_golem("testgolembrochure", project_hook = brochure::golem_hook)
setwd("testgolembrochure")

path_dummy_golem <- tempfile(pattern = "dummygolem")

golem::create_golem(
path = path_dummy_golem,
open = FALSE,
project_hook = brochure::golem_hook
)

old_wd <- setwd(path_dummy_golem)
on.exit({
unlink(path_dummy_golem, TRUE, TRUE)
setwd(old_wd)
})

expect_true(
file.exists("R/mod_home.R")
)
Expand All @@ -99,31 +122,56 @@ test_that("golem_hook works", {
"R/mod_home.R"
)
)
expect_equal(
readLines(
system.file(
"golem/run_app.R",
package = "brochure"
)
),
readLines(
"R/run_app.R"

remove_app_title_line <- function(run_app_lines) {
grep(
pattern = "app_title = ",
x = run_app_lines,
value = TRUE,
invert = TRUE
)
}
run_app_brochure_template <-readLines(
system.file(
"golem/run_app.R",
package = "brochure"
)
)

run_app_dummy_golem <- readLines("R/run_app.R")
## run_app is properly copied and...
expect_equal(
remove_app_title_line(run_app_brochure_template),
remove_app_title_line(run_app_dummy_golem)
)
# ...app_title was modified
expect_error(
expect_equal(
run_app_brochure_template,
run_app_dummy_golem
),
regexp = "app_title = "
)

# Module template was added in calls to golem::add_module() in 02_dev.R
expect_true(
grepl(
"brochure",
"module_template = brochure::new_page",
paste(readLines("dev/02_dev.R"), collapse = " ")
)
)

})
```


```{r development-inflate, eval=FALSE}
# Run but keep eval=FALSE to avoid infinite loop
# Execute in the console directly
fusen::inflate(flat_file = "dev/flat_golem_hook.Rmd", vignette_name = NA, document = FALSE)
fusen::inflate(
flat_file = "dev/flat_golem_hook.Rmd",
vignette_name = NA,
check = FALSE,
document = FALSE
)
```

3 changes: 2 additions & 1 deletion man/page.Rd

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

62 changes: 45 additions & 17 deletions tests/testthat/test-golem_hook.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Generated by fusen: do not edit by hand
# WARNING - Generated by {fusen} from /dev/flat_golem_hook.Rmd: do not edit by hand

test_that("golem_hook works", {

skip_if_not_installed("golem")
old <- setwd(tempdir())
on.exit(setwd(old))
unlink("testgolembrochure", TRUE, TRUE)
golem::create_golem("testgolembrochure", project_hook = brochure::golem_hook)
setwd("testgolembrochure")

path_dummy_golem <- tempfile(pattern = "dummygolem")

golem::create_golem(
path = path_dummy_golem,
open = FALSE,
project_hook = brochure::golem_hook
)

old_wd <- setwd(path_dummy_golem)
on.exit(setwd(old_wd))

expect_true(
file.exists("R/mod_home.R")
)
Expand All @@ -24,22 +32,42 @@ test_that("golem_hook works", {
"R/mod_home.R"
)
)
expect_equal(
readLines(
system.file(
"golem/run_app.R",
package = "brochure"
)
),
readLines(
"R/run_app.R"

remove_app_title_line <- function(run_app_lines) {
grep(
pattern = "app_title = ",
x = run_app_lines,
value = TRUE,
invert = TRUE
)
}
run_app_brochure_template <-readLines(
system.file(
"golem/run_app.R",
package = "brochure"
)
)

run_app_dummy_golem <- readLines("R/run_app.R")
## run_app is properly copied and...
expect_equal(
remove_app_title_line(run_app_brochure_template),
remove_app_title_line(run_app_dummy_golem)
)
# ...app_title was modified
expect_error(
expect_equal(
run_app_brochure_template,
run_app_dummy_golem
),
regexp = "app_title = "
)

# Module template was added in calls to golem::add_module() in 02_dev.R
expect_true(
grepl(
"brochure",
"module_template = brochure::new_page",
paste(readLines("dev/02_dev.R"), collapse = " ")
)
)

})
Loading