From bc70053a6651dd2a81dbc325083161d65cbc71a7 Mon Sep 17 00:00:00 2001 From: Jakub Sobolewski Date: Thu, 29 Jun 2023 15:17:58 +0200 Subject: [PATCH] refactor: live example cards --- inst/examples/dashboard/app.R | 4 ++-- inst/examples/dashboard/examples.R | 17 ++++++++++++----- inst/examples/dashboard/utils.R | 5 ++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/inst/examples/dashboard/app.R b/inst/examples/dashboard/app.R index 87eeb61c..10b37532 100644 --- a/inst/examples/dashboard/app.R +++ b/inst/examples/dashboard/app.R @@ -22,7 +22,7 @@ router_page_elements <- append( route("/", homePage), route("about", aboutPage) ), - map(examples_routes, "router") + map(examples_routes, "route") ) router_page <- do.call(router_ui, router_page_elements) @@ -65,7 +65,7 @@ sass( server <- function(input, output, session) { router_server() examples_routes %>% - map("server") %>% + map("servers") %>% flatten() %>% iwalk(function(server, id) server(id)) } diff --git a/inst/examples/dashboard/examples.R b/inst/examples/dashboard/examples.R index 4b40f0b5..33ae6655 100644 --- a/inst/examples/dashboard/examples.R +++ b/inst/examples/dashboard/examples.R @@ -92,6 +92,7 @@ readExample <- function(path) { list(code = code, ui = module$ui, server = module$server) } +#' Splits `text` into paragraphs. makeText <- function(text) { strsplit(text, "\\n\\n")[[1]] %>% map(Text) %>% @@ -113,8 +114,14 @@ makeExamplePage <- function(name, example) { makeLiveExamplePage <- function(example, id) { tagList( - makeCard("Live example", div(style = "padding: 20px", example$ui(id))), - makeCard("Live example code", pre(example$code)) + makeCard( + title = Text("Live example", variant = "large"), + content = tagList( + example$ui(id), + Separator(), + pre(example$code) + ) + ) ) } @@ -124,7 +131,7 @@ makeExampleRoute <- function(name) { full.names = TRUE ) # Match on component names with optional digits at the end - pattern <- paste0("^", name, "([0-9]+)?.R") + pattern <- paste0("^", name, "[0-9]*.R") path <- examples_files[grepl(pattern, basename(examples_files))] examples_names <- tools::file_path_sans_ext(basename(path)) example <- path %>% @@ -132,8 +139,8 @@ makeExampleRoute <- function(name) { set_names(examples_names) list( - server = map(example, "server"), - router = route( + servers = map(example, "server"), + route = route( path = name, ui = makeExamplePage( name = name, diff --git a/inst/examples/dashboard/utils.R b/inst/examples/dashboard/utils.R index 8547be9b..0d7aa601 100644 --- a/inst/examples/dashboard/utils.R +++ b/inst/examples/dashboard/utils.R @@ -13,6 +13,9 @@ makeCard <- function(title, content) { div( class = "card ms-depth-8", Text(variant = "large", title, block = TRUE), - content + div( + style = "margin-top: 10px;", + content + ) ) }