Skip to content

Commit

Permalink
wip: route handling via regex
Browse files Browse the repository at this point in the history
This is a work in progress.
The goal is to allow for route handling via regex.
This will allow for more flexibility in the routing of requests.

Issue #3
  • Loading branch information
ColinFay committed Mar 22, 2023
1 parent 332ba62 commit ecd7157
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
5 changes: 3 additions & 2 deletions R/brochureApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ brochureApp <- function(
request$PATH_INFO,
...multipage$pages
)$ui

if (is.function(ui)) {
ui <- ui(request)
}

...multipage_opts$wrapped(
tags$head(
shiny::tags$head(
tagList(
shiny::includeScript(
system.file(
Expand Down Expand Up @@ -100,7 +101,7 @@ brochureApp <- function(
)

set_params(
brochure_server,
brochure_server$extract(),
session = session
)

Expand Down
2 changes: 1 addition & 1 deletion R/match_route.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
match_route <- function(
href,
routes
) {
) {
for (route in routes) {
if (route$matches(href)) {
return(route)
Expand Down
2 changes: 1 addition & 1 deletion R/route.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Route <- R6::R6Class(
)[[1]]
list(
route = matches[1],
params = matches[-1]
params = as.list(matches[-1])
)
}
)
Expand Down
11 changes: 6 additions & 5 deletions dev/flat_handler.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ library(testthat)
# Load already included functions if relevant
pkgload::load_all(export_all = FALSE)
```
## Routing in `{brochure}`

# Route

Expand Down Expand Up @@ -92,7 +93,7 @@ Route <- R6::R6Class(
)[[1]]
list(
route = matches[1],
params = matches[-1]
params = as.list(matches[-1])
)
}
)
Expand Down Expand Up @@ -162,7 +163,7 @@ test_that("Route works", {
)
expect_equal(
extracted$params,
c(id = "aaa", postid = "aaa")
list(id = "aaa", postid = "aaa")
)
r_with_regex <- Route$new(
Expand Down Expand Up @@ -198,7 +199,7 @@ test_that("Route works", {
)
expect_equal(
extracted$params,
character(0)
list()
)
# Test the `initialize` method with missing arguments
Expand Down Expand Up @@ -550,7 +551,7 @@ test_that("set_params works", {
session <- shiny::MockShinySession$new()
expect_equal(
set_params(
list(params = c(id = "aaa", postid = "aaa")),
list(params = list(id = "aaa", postid = "aaa")),
session = session
),
NULL
Expand All @@ -559,7 +560,7 @@ test_that("set_params works", {
get_params(
session
),
c(id = "aaa", postid = "aaa")
list(id = "aaa", postid = "aaa")
)
})
```
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-params.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("set_params works", {
session <- shiny::MockShinySession$new()
expect_equal(
set_params(
list(params = c(id = "aaa", postid = "aaa")),
list(params = list(id = "aaa", postid = "aaa")),
session = session
),
NULL
Expand All @@ -13,6 +13,6 @@ test_that("set_params works", {
get_params(
session
),
c(id = "aaa", postid = "aaa")
list(id = "aaa", postid = "aaa")
)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-route.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("Route works", {
)
expect_equal(
extracted$params,
c(id = "aaa", postid = "aaa")
list(id = "aaa", postid = "aaa")
)

r_with_regex <- Route$new(
Expand Down Expand Up @@ -87,7 +87,7 @@ test_that("Route works", {
)
expect_equal(
extracted$params,
character(0)
list()
)

# Test the `initialize` method with missing arguments
Expand Down

0 comments on commit ecd7157

Please sign in to comment.