Skip to content

Commit

Permalink
from ambhtmx_app to ambhtmx
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosell committed Aug 5, 2024
1 parent 6adc6ff commit 9b17d84
Show file tree
Hide file tree
Showing 67 changed files with 1,004 additions and 237 deletions.
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Suggests:
here,
pak,
pkgdown (>= 2.1.0),
plotly,
scilis (>= 0.0.0.9000),
signaculum (>= 0.0.0.9000),
testthat,
usethis,
withr,
zeallot
Imports:
ambiorix (>= 2.1.0),
Expand All @@ -32,17 +32,20 @@ Imports:
dplyr,
glue,
htmltools,
htmlwidgets,
pool,
purrr,
readr,
rlang,
RSQLite,
stringr,
tibble,
uwu (>= 0.0.0.9000)
uwu (>= 0.0.0.9000),
withr
Remotes:
devOpifex/ambiorix,
devOpifex/scilis,
devOpifex/signaculum,
JosiahParry/uwu
URL: https://jrosell.github.io/ambhtmx, https://github.com/jrosell/ambhtmx
BugReports: https://github.com/jrosell/ambhtmx/issues
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export(amb_button)
export(amb_card)
export(amb_input_text)
export(ambhtmx_app)
export(ambhtmx)
export(button)
export(form)
export(input)
Expand All @@ -17,7 +17,7 @@ export(process_login_get)
export(process_login_post)
export(process_logout_get)
export(render_page)
export(render_plot)
export(render_png)
export(render_tags)
export(script)
export(script_from_js_tpl)
Expand Down
2 changes: 1 addition & 1 deletion R/ambhtmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param render_row function to be stored as a model method (optional)
#' @returns A list with the ambiorix app, the running context and the model methods.
#' @export
ambhtmx_app <- \(
ambhtmx <- \(
dbname = NULL,
value = tibble::tibble(),
protocol = NULL,
Expand Down
7 changes: 4 additions & 3 deletions R/extra-components.R → R/components-amb.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Generate component
#'
#' @rdname component
#' @keywords components
#' @rdname components
#' @param ... htmlobjects to add
#' @param class to add more classes to the card
#' @param title to customeize the title text
Expand Down Expand Up @@ -30,7 +31,7 @@ amb_card <- \(
)
}

#' @rdname component
#' @rdname components
#' @param ... htmlobjects to add
#' @param id for the label and the input
#' @param label customize
Expand Down Expand Up @@ -68,7 +69,7 @@ amb_input_text <- \(
)
}

#' @rdname component
#' @rdname components
#' @param ... htmlobjects to add
#' @param class customize
#' @param type customize
Expand Down
27 changes: 15 additions & 12 deletions R/extra-tags.R → R/components-tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' `<article>`), use the `tags` list collection (e.g., `tags$article()`). To
#' create other non HTML/SVG tags, use the lower-level `tag()` constructor.
#'
#' @name builder
#' @name tags
#' @param ... Tag attributes (named arguments) and children (unnamed arguments).
#' A named argument with an `NA` value is rendered as a boolean attributes
#' (see example). Children may include any combination of:
Expand All @@ -27,52 +27,54 @@
#' @return A `list()` with a `shiny.tag` class that can be converted into an
#' HTML string via `as.character()` and saved to a file with `save_html()`.
#'
#' @rdname builder
#' @rdname tags
#' @keywords components
#' @export
button <- htmltools::tags$button

#' @rdname builder
#' @rdname tags
#' @export
textarea <- htmltools::tags$textarea

#' @rdname builder
#' @rdname tags
#' @export
input <- htmltools::tags$input

#' @rdname builder
#' @rdname tags
#' @export
label <- htmltools::tags$label

#' @rdname builder
#' @rdname tags
#' @export
nav <- htmltools::tags$nav

#' @rdname builder
#' @rdname tags
#' @export
li <- htmltools::tags$li

#' @rdname builder
#' @rdname tags
#' @export
ul <- htmltools::tags$ul

#' @rdname builder
#' @rdname tags
#' @export
ol <- htmltools::tags$ol

#' @rdname builder
#' @rdname tags
#' @export
form <- htmltools::tags$form

#' @rdname builder
#' @rdname tags
#' @export
style <- htmltools::tags$style

#' @rdname builder
#' @rdname tags
#' @export
script <- htmltools::tags$script

#' Generate style from css template
#'
#' @keywords components
#' @rdname style_from_css_tpl
#' @param file path to a js file
#' @param ... mutiple named arguments with the value to replaces
Expand Down Expand Up @@ -113,6 +115,7 @@ style_tpl_css_vars_replace <- \(content, ...){

#' Generate script from js template
#'
#' @keywords components
#' @rdname script_from_js_tpl
#' @param file path to a js file
#' @param ... mutiple named arguments with the value to replace
Expand Down
10 changes: 6 additions & 4 deletions R/dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ rebuild_docs_and_check <- function() {
"usethis",
"ggplot2",
"zeallot",
"withr",
"testthat",
"dbplyr",
"here"
"here",
"plotly"
)
suggests_packages |> purrr::map(
\(x){usethis::use_package(x, type = "Suggests"); x}
Expand All @@ -57,7 +57,9 @@ rebuild_docs_and_check <- function() {
"RSQLite",
"pool",
"readr",
"uwu"
"uwu",
"withr",
"htmlwidgets"
)
imports_packages |> purrr::map(
\(x){usethis::use_package(x, type = "Imports"); x}
Expand All @@ -78,7 +80,7 @@ rebuild_docs_and_check <- function() {
usethis::use_dev_package("uwu", remote = "JosiahParry/uwu", type = "Imports")

write(
"URL: https://jrosell.github.io/ambhtmx, https://github.com/jrosell/ambhtmx",
"URL: https://jrosell.github.io/ambhtmx, https://github.com/jrosell/ambhtmx\nBugReports: https://github.com/jrosell/ambhtmx/issues",
file = "DESCRIPTION",
append = TRUE
)
Expand Down
51 changes: 27 additions & 24 deletions R/render.R → R/rendering.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#' Render a custom page with a custom title and main content
#'
#' @keywords render
#' @keywords rendering
#' @param main htmltools object of the body of the html page
#' @param page_title the title tag contents of the page
#' @param head_tags optional htmltools object of the head of the html page
Expand Down Expand Up @@ -62,7 +62,7 @@ render_page <- \(main = NULL, page_title = NULL, head_tags = NULL) {

#' Render a page and send the respose
#'
#' @keywords render
#' @keywords rendering
#' @param res response object
#' @param main htmltools object of the body of the html page
#' @param ... other paramters to the render page function
Expand All @@ -81,7 +81,7 @@ send_page <- \(main = NULL, res, ...) {

#' Render a custom page with a custom title and main content
#'
#' @keywords render
#' @keywords rendering
#' @param main htmltools object to render
#' @param res response object
#' @param ... htmltools object to render
Expand All @@ -101,6 +101,30 @@ send_tags <- \(main = NULL, res, ...) {
res$send(html)
}


#' Render tags to character vector
#'
#' @keywords rendering
#' @param ... one or more htmltools objects.
#' @returns a character representation of input
#' @export
render_tags <- \(...) {
as.character(htmltools::tagList(...))
}

#' Render a png image to a img tag
#'
#' @keywords rendering
#' @param p a ggplot or another object that can be printed and captured as a png image
#' @returns img htmltools tag with a data encoded src attribute
#' @export
render_png <- \(p){
grDevices::png(p_file <- tempfile(fileext = ".png")); print(p); grDevices::dev.off()
p_txt <- b64::encode_file(p_file)
tags$img(src = glue::glue("data:image/png;base64,{p_txt}"))
}


#' @noRd
replace_hx_attrs <- function(x) {
if (is.list(x)) {
Expand Down Expand Up @@ -185,24 +209,3 @@ render_html <- \(htmx_tags){
return(paste0(html, collapse = ""))
}


#' Render tags to character vector
#'
#' @keywords render
#' @param ... one or more htmltools objects.
#' @returns a character representation of input
#' @export
render_tags <- \(...) {
as.character(htmltools::tagList(...))
}

#' Render imatge or ggplot to image tag
#'
#' @param p a ggplot or another object that can be printed and captured as a png image
#' @returns img htmltools tag with a data encoded src attribute
#' @export
render_plot <- \(p){
grDevices::png(p_file <- tempfile(fileext = ".png")); print(p); grDevices::dev.off()
p_txt <- b64::encode_file(p_file)
tags$img(src = glue::glue("data:image/png;base64,{p_txt}"))
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,34 @@ AMBHTMX_PORT=<to change port default 3000>
## Code examples

### [Incrementing a counter](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/01-counter.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/01.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/01-counter.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/01.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/01-counter.R)

### [Updating a ggplot2](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/02-ggplot2.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/02.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/02-ggplot2.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/02.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/02-ggplot2.R)

### [Interacting with an slider](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/03-slider.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/03.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/03-slider.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/03.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/03-slider.R)

### [Using SQLite to build a TODO app](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/04-todo.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/04.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/04-todo.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/04.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/04-todo.R)

### [Live Reloading using npm and nodemon](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/05-live.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/05.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/05-live.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/05.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/05-live.R)

### [Single user and password autentication](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/06-basic-auth.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/06.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/06-basic-auth.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/06.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/06-basic-auth.R)


### [Password protected CRUD (Create, Read, Update, and Delete) example with ambhtmx](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/07-crud.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/07.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/07-crud.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/07.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/07-crud.R)


### [Cleaner and shorter code hx_ to hx- replacement](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/08-hx_attributes.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/08.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/08-hx_attributes.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/08.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/08-hx_attributes.R)


### [Customizable web components: Port to R of card3d from FastHTML](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/09-card3d.R)
[![](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/09.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/09-card3d.R)
[![example](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/09.png)](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/09-card3d.R)

* [Python implementation](https://github.com/jrosell/ambhtmx/blob/main/inst/examples/09-card3d.py) ([Screenshot](https://raw.githubusercontent.com/jrosell/ambhtmx/main/inst/examples/09py.png)). Original python code credit to [AnswerDotAI/fasthtml](https://fastht.ml/), Design credit: https://codepen.io/markmiro/pen/wbqMPa

Expand Down
41 changes: 41 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,44 @@ url: https://jrosell.github.io/ambhtmx

template:
bootstrap: 5


home:
links:
- text: ambiorix reference
href: https://ambiorix.dev/docs/ambiorix
- text: htmltools reference
href: https://rstudio.github.io/htmltools/reference/index.html
- text: htmx reference
href: https://htmx.org/reference/


reference:

- title: Main ambhtmx functions
contents:
- has_keyword("ambhtmx")

- title: Authentication functions
desc: >
Some functions to help process login, logout and authentication.
contents:
- has_keyword("auth")

- title: Components
desc: >
More tags and and tools to build new components and pages.
contents:
- has_keyword("components")

- title: Rendering
desc: >
Some functions to help rendering and processing tags and pages.
contents:
- has_keyword("rendering")


development:
mode: auto


2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

Loading

0 comments on commit 9b17d84

Please sign in to comment.