Skip to content

Commit ad6c3bf

Browse files
authored
Merge pull request #116 from ambiorix-web/115-prepare-for-cran
115 prepare for cran
2 parents 9912089 + 5143e14 commit ad6c3bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+624
-387
lines changed

CRAN-SUBMISSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 2.1.1
2-
Date: 2024-05-23 15:09:58 UTC
3-
SHA: d09a2416c75f8ff57fc320c60e48bbb0b2c2cf46
1+
Version: 2.2.0
2+
Date: 2025-03-13 10:51:19 UTC
3+
SHA: af4c92f41ab95127d65e236edffbb2ce4c19acd3

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ambiorix
22
Title: Web Framework Inspired by 'Express.js'
3-
Version: 2.1.1
3+
Version: 2.2.0
44
Authors@R:
55
c(
66
person(given = "John",
@@ -41,6 +41,6 @@ Suggests:
4141
commonmark,
4242
htmlwidgets,
4343
testthat (>= 3.0.0)
44-
URL: https://github.com/devOpifex/ambiorix, https://ambiorix.dev
45-
BugReports: https://github.com/devOpifex/ambiorix/issues
44+
URL: https://github.com/ambiorix-web/ambiorix, https://ambiorix.dev
45+
BugReports: https://github.com/ambiorix-web/ambiorix/issues
4646
Config/testthat/edition: 3

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export(copy_websocket_client)
3333
export(create_dockerfile)
3434
export(default_cookie_parser)
3535
export(forward)
36-
export(get_websocket_clients)
3736
export(import)
3837
export(jobj)
3938
export(mockRequest)

NEWS.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
# ambiorix 2.2.0
2+
3+
__New Features__
4+
5+
- Enable nesting of Routers, [pull/73](https://github.com/ambiorix-web/ambiorix/pull/73).
6+
- Enable full support for htmltools tags, no need for html templates, [pull/78](https://github.com/ambiorix-web/ambiorix/pull/78), [pull/92](https://github.com/ambiorix-web/ambiorix/pull/92).
7+
- Add `engine()` method set custom renderers, [pull/66](https://github.com/ambiorix-web/ambiorix/pull/66).
8+
- Add `set_error()` method to set a global error handler, [pull/64](https://github.com/ambiorix-web/ambiorix/pull/64).
9+
- Add a default error handler, [pull/88](https://github.com/ambiorix-web/ambiorix/pull/88).
10+
11+
__Changes__
12+
13+
- Resolve port to bind server on in a specific order, [pull/75](https://github.com/ambiorix-web/ambiorix/pull/75).
14+
- Switch to {yyjsonr} for faster serialization & de-serialization, [pull/100](https://github.com/ambiorix-web/ambiorix/pull/100).
15+
- Switch to {webutils} for faster parsing of multipart & urlencoded request bodies, [pull/100](https://github.com/ambiorix-web/ambiorix/pull/100).
16+
- Continually process requests using `httpuv::service()` instead of a while loop, [pull/98](https://github.com/ambiorix-web/ambiorix/pull/98).
17+
- Remove syntactic sugar to improve backwards compatibility with R <= 4.1.0, [pull/113](https://github.com/ambiorix-web/ambiorix/pull/113).
18+
- Deprecate `create_dockerfile()`, [pull/116](https://github.com/ambiorix-web/ambiorix/pull/116)
19+
20+
__Bug Fixes__
21+
22+
- Fix bug hindering change of the max body size of a request,
23+
[pull/69](https://github.com/ambiorix-web/ambiorix/pull/69).
24+
- Fix issue causing pattern matching in routes to throw error, [pull/82](https://github.com/ambiorix-web/ambiorix/pull/82), [pull/110](https://github.com/ambiorix-web/ambiorix/pull/110).
25+
- Fix bug on error condition messaging when promise evaluation fails, [pull/88](https://github.com/ambiorix-web/ambiorix/pull/88).
26+
127
# ambiorix 2.1.1
228

329
- Added `cache_templates` method to cache templates
@@ -6,7 +32,7 @@ in memory.
632
rendering.
733
- Custom renderers (`as_renderer`) are now more robust.
834
- Add `limit` field to protect against large uploads.
9-
- Fix issue with setting custom websocket handler [#62](https://github.com/devOpifex/ambiorix/issues/62).
35+
- Fix issue with setting custom websocket handler [#62](https://github.com/ambiorix-web/ambiorix/issues/62).
1036
- Add `engine` method on router to set custom renderers (`use` deprecated for custom renderers).
1137

1238
# ambiorix 2.1.0
@@ -38,16 +64,16 @@ No longer force render data as JSON if using an HTML template.
3864
- Export `serialise`
3965
- Fixed issue where wrong path pattern was matched.
4066
- Catch error if no route is specified.
41-
- Do not force body to character fixes [#44](https://github.com/devOpifex/ambiorix/issues/44)
42-
- Do no force content type on response fixes [#45](https://github.com/devOpifex/ambiorix/issues/45)
67+
- Do not force body to character fixes [#44](https://github.com/ambiorix-web/ambiorix/issues/44)
68+
- Do no force content type on response fixes [#45](https://github.com/ambiorix-web/ambiorix/issues/45)
4369
- Deprecate passing headers to `response` or `send`-like functions, use
4470
`header` method.
4571
- Deprecate `set_header` in favour of `header` method.
4672
- Added family of `header_content*` methods to easily set `Content-Type`.
4773
- Request `HEADERS` is always a `list`.
48-
- Deprecate `set` and `get` on Response and Request, this is no longer
74+
- Deprecate `set` and `get` on Response and Request, this is no longer
4975
needed the environments are no longer locked; `res$myVar <- 2L`.
50-
- Deprecate `status` argument of responses, the active binding should
76+
- Deprecate `status` argument of responses, the active binding should
5177
be used instead; `res$status <- 404L`.
5278
- Partially improved route matching.
5379
- Allow customising the path to pattern converter.
@@ -64,9 +90,9 @@ of said router.
6490
- Empty cookie is empty list instead of empty string.
6591
- Added `mockRequest` to for testing purposes.
6692
- Fixed `port`, `host`, and `websocket` active bindings.
67-
- Add ability to create custom renderer, see
68-
[jader](https://github.com/devOpifex/jader), and
69-
[pugger](https://github.com/devOpifex/pugger).
93+
- Add ability to create custom renderer, see
94+
[jader](https://github.com/ambiorix-web/jader), and
95+
[pugger](https://github.com/ambiorix-web/pugger).
7096

7197
# ambiorix 2.0.0
7298

@@ -76,7 +102,7 @@ The `render` and `send_file` methods of the `Response` object now
76102
expect the full path to the template, with the file extension.
77103
Where one would before `res$render("home")`, now one
78104
`res$render("templates/home.html")`.
79-
Similarly, in said templates, to import partials,
105+
Similarly, in said templates, to import partials,
80106
use full path relative to the template in which the partial is used
81107
e.g.: from `[! header.html !]` to `[! partials/header.html !]`.
82108

@@ -90,15 +116,15 @@ locking variables when using `set`.
90116
- Remove the deprecated `Logger` class, see [log](https://github.com/devOpifex/log) package.
91117
- Pass `host` to free port fetch function.
92118
- Add hidden option to force change port for upcoming related service.
93-
- Internals of calls reworked to share response object.
94-
This is how it should always have worked, it allows middlewares to
119+
- Internals of calls reworked to share response object.
120+
This is how it should always have worked, it allows middlewares to
95121
updatre request and response to be used/passed to subsequent calls.
96122
- Middleware check for run has been fixed.
97123
- Document and export the `Response` class.
98124
- Added pre-hook to response.
99125
- Document and export `Request` class.
100126
- `set` and `get` methods on `Request` and `Response` accept character
101-
strings as `name`.
127+
strings as `name`.
102128
- Use R 4.1.0 + add `Depends`
103129
- Allow passing a list of functions to `use` to easily se multiple
104130
middlewares at once.
@@ -124,19 +150,19 @@ with `sprintf`.
124150
# ambiorix 1.0.2
125151

126152
- Reaches CRAN
127-
- Removed `create_ambiorix`, see [ambiorix.generator](https://github.com/devOpifex/ambiorix.generator).
128-
- Removed `add_template`, see [ambiorix.generator](https://github.com/devOpifex/ambiorix.generator).
153+
- Removed `create_ambiorix`, see [ambiorix.generator](https://github.com/ambiorix-web/ambiorix.generator).
154+
- Removed `add_template`, see [ambiorix.generator](https://github.com/ambiorix-web/ambiorix.generator).
129155
- Deprecate the `Logger` class in favour of the [log](https://github.com/devOpifex/log) package.
130-
- Fixed `parse_json` [#36](https://github.com/devOpifex/ambiorix/issues/36)
156+
- Fixed `parse_json` [#36](https://github.com/ambiorix-web/ambiorix/issues/36)
131157

132158
# ambiorix 1.0.1
133159

134-
- Deprecate `create_ambiorix`: moving to [ambiorix.generator](https://github.com/devOpifex/ambiorix.generator) package.
135-
- Deprecate `add_template`: moving to [ambiorix.generator](https://github.com/devOpifex/ambiorix.generator) package.
160+
- Deprecate `create_ambiorix`: moving to [ambiorix.generator](https://github.com/ambiorix-web/ambiorix.generator) package.
161+
- Deprecate `add_template`: moving to [ambiorix.generator](https://github.com/ambiorix-web/ambiorix.generator) package.
136162
- Added `all` method to define route and handler for all methods `GET`, `POST`, `PUT`, `DELETE`, and `PATCH`.
137163
- The `use` method now accepts a function which is run every time the server receives a request.
138164
- Add `set` and `get` to request to add and retrieve params (namely with the middleware)
139-
- Fix `check_installed`, see [#33](https://github.com/devOpifex/ambiorix/issues/33)
165+
- Fix `check_installed`, see [#33](https://github.com/ambiorix-web/ambiorix/issues/33)
140166

141167
# ambiorix 1.0.0
142168

R/content.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' )
1616
#'
1717
#' @name content
18-
#'
18+
#' @return Length 1 character vector.
1919
#' @export
2020
content_html <- function() {
2121
"text/html"

R/cookie.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@
33
#' Parses the cookie string.
44
#'
55
#' @param req A [Request].
6-
#'
6+
#' @examples
7+
#' if (interactive()) {
8+
#' library(ambiorix)
9+
#'
10+
#' #' Handle GET at '/greet'
11+
#' #'
12+
#' #' @export
13+
#' say_hello <- function(req, res) {
14+
#' cookies <- default_cookie_parser(req)
15+
#' print(cookies)
16+
#'
17+
#' res$send("hello there!")
18+
#' }
19+
#'
20+
#' app <- Ambiorix$new()
21+
#' app$get("/greet", say_hello)
22+
#' app$start()
23+
#' }
24+
#'
725
#' @return A `list` of key value pairs or cookie values.
8-
#'
926
#' @export
1027
default_cookie_parser <- function(req) {
1128
cookie_new <- list()
@@ -18,7 +35,7 @@ default_cookie_parser <- function(req) {
1835

1936
split <- strsplit(req$HTTP_COOKIE, ";")[[1]]
2037
split <- strsplit(split, "=")
21-
for(i in 1:length(split)) {
38+
for(i in seq_along(split)) {
2239
value <- trimws(split[[i]])
2340

2441
if(length(value) < 2)
@@ -54,6 +71,7 @@ default_cookie_parser <- function(req) {
5471
#' app <- Ambiorix$new()
5572
#' app$use(parser)
5673
#'
74+
#' @return Object of class "cookieParser".
5775
#' @export
5876
as_cookie_parser <- function(fn) {
5977
assert_that(not_missing(fn))
@@ -76,6 +94,7 @@ print.cookieParser <- function(x, ...) {
7694
}
7795

7896
#' @keywords internal
97+
#' @noRd
7998
is_cookie_parser <- function(obj) {
8099
inherits(obj, "cookieParser")
81100
}
@@ -99,6 +118,7 @@ is_cookie_parser <- function(obj) {
99118
#' app <- Ambiorix$new()
100119
#' app$use(prep)
101120
#'
121+
#' @return Object of class "cookiePreprocessor".
102122
#' @export
103123
as_cookie_preprocessor <- function(fn) {
104124
assert_that(not_missing(fn))
@@ -154,6 +174,7 @@ is_cookie_preprocessor <- function(obj) {
154174
#' attacks (CSRF). Accepts `Strict`, `Lax`, or `None`.
155175
#'
156176
#' @keywords internal
177+
#' @noRd
157178
cookie <- function(
158179
name,
159180
value,

R/docker.R

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
#' @details Reads the `DESCRIPTION` file of the project to produce the `Dockerfile`.
1010
#'
1111
#' @param port,host Port and host to serve the application.
12+
#' @param file_path String. Path to file to write to.
1213
#'
1314
#' @examples
14-
#' \dontrun{create_dockerfile()}
15+
#' if (interactive()) {
16+
#' create_dockerfile(port = 5000L, host = "0.0.0.0", file_path = tempfile())
17+
#' # create_dockerfile(port = 5000L, host = "0.0.0.0", file_path = "Dockerfile")
18+
#' }
1519
#'
20+
#' @return `NULL` (invisibly)
1621
#' @export
17-
create_dockerfile <- function(port, host = "0.0.0.0"){
22+
create_dockerfile <- function(port, host = "0.0.0.0", file_path){
23+
.Deprecated(msg = "'create_dockerfile' is deprecated. Please write the Dockerfile manually.")
1824
assert_that(has_file("DESCRIPTION"))
1925
assert_that(not_missing(port))
26+
assert_that(not_missing(file_path))
2027

2128
cli::cli_alert_warning("Ensure your {.file DESCRIPTION} file is up to date with {.fun devtools::check}")
2229

@@ -25,30 +32,14 @@ create_dockerfile <- function(port, host = "0.0.0.0"){
2532

2633
dockerfile <- c(
2734
"FROM jcoenep/ambiorix",
28-
"RUN echo \"options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest'))\" >> /usr/local/lib/R/etc/Rprofile.site",
29-
"RUN R -e 'install.packages(\"remotes\")'"
35+
"RUN echo \"options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest'))\" >> /usr/local/lib/R/etc/Rprofile.site"
3036
)
3137

3238
# CRAN packages
3339
desc <- read.dcf("DESCRIPTION")
3440
pkgs <- desc[, "Imports"]
3541
pkgs <- strsplit(pkgs, ",")[[1]]
3642
pkgs <- gsub("\\\n", "", pkgs)
37-
cran <- sapply(pkgs, function(pkg){
38-
sprintf("RUN R -e \"install.packages('%s')\"", pkg)
39-
})
40-
41-
# remotes
42-
rmts <- tryCatch(desc[, 'Remotes'], error = function(e) NULL)
43-
if(!is.null(rmts)){
44-
rmts <- strsplit(rmts, ",")[[1]]
45-
rmts <- gsub("\\\n", "", rmts)
46-
rmts <- rmts[rmts != "ambiorix"]
47-
rmts <- sapply(rmts, function(pkg){
48-
sprintf("RUN R -e \"remotes::install_github('%s', force=FALSE)\"", pkg)
49-
})
50-
cran <- c(cran, rmts)
51-
}
5243

5344
cmd <- sprintf(
5445
"CMD R -e \"options(ambiorix.host='%s', 'ambiorix.port'=%s);source('app.R')\"",
@@ -57,14 +48,13 @@ create_dockerfile <- function(port, host = "0.0.0.0"){
5748

5849
dockerfile <- c(
5950
dockerfile,
60-
cran,
6151
"COPY . .",
6252
cmd
6353
)
6454

65-
x <- writeLines(dockerfile, "Dockerfile")
55+
x <- writeLines(dockerfile, file_path)
6656

6757
cli::cli_alert_success("Created {.file Dockerfile}")
6858

6959
invisible()
70-
}
60+
}

R/import.R

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#' Import Files
2-
#'
2+
#'
33
#' Import all R-files in a directory.
4-
#'
4+
#'
55
#' @param ... Directory from which to import `.R` or `.r` files.
6-
#'
7-
#' @examples
8-
#' \dontrun{import("views")}
9-
#'
6+
#'
7+
#' @examples
8+
#' if (interactive()) {
9+
#' import("views")
10+
#' }
11+
#'
1012
#' @return Invisibly returns `NULL`.
11-
#'
13+
#'
1214
#' @export
13-
import <- function(...){{
14-
files <- fs::dir_ls(..., regexp = "\\.R$|\\.r$")
15+
import <- function(...) {
16+
files <- fs::dir_ls(..., regexp = "\\.R$|\\.r$")
1517
sapply(files, source)
1618
invisible()
17-
}}
19+
}

R/log.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,21 @@ new_log <- function(
5151
#' [log::Logger].
5252
#'
5353
#' @name set_log
54+
#' @return The `log` object.
55+
#' @examples
56+
#' # define custom loggers:
57+
#' info_logger <- log::Logger$new("INFO")
58+
#' success_logger <- log::Logger$new("SUCCESS")
59+
#' error_logger <- log::Logger$new("ERROR")
5460
#'
61+
#' info_logger$log("This is an info message.")
62+
#' success_logger$log("This is a success message.")
63+
#' error_logger$log("This is an error message.")
64+
#'
65+
#' # set custom loggers for Ambiorix:
66+
#' set_log_info(info_logger)
67+
#' set_log_success(success_logger)
68+
#' set_log_error(error_logger)
5569
#' @export
5670
set_log_info <- function(log) {
5771
assert_that(not_missing(log))
@@ -83,21 +97,25 @@ set_log_error <- function(log) {
8397
#' CLI Symbols for log
8498
#'
8599
#' @keywords internal
100+
#' @noRd
86101
success <- function() {
87102
cli::col_green(cli::symbol$tick)
88103
}
89104

90105
#' @keywords internal
106+
#' @noRd
91107
error <- function() {
92108
cli::col_red(cli::symbol$cross)
93109
}
94110

95111
#' @keywords internal
112+
#' @noRd
96113
info <- function() {
97114
cli::col_blue(cli::symbol$info)
98115
}
99116

100117
#' @keywords internal
118+
#' @noRd
101119
warn <- function() {
102120
cli::col_yellow(cli::symbol$warning)
103121
}

0 commit comments

Comments
 (0)