Comments (4)
Hey @abelborges,
Thanks a lot for this! Awesome.
I love the approach of returning a list with a function and all, smart.
Let me take a closer look into that and see how it could work inside brochure
from brochure.
Idea:
- Add a page as
/this/{id}/
- is turned in the name to
/this/([^/])/
- is extracted by handlers and UI and server
How does express.JS does that under the hood? I feel like I'm missing something.
Basically the idea is to define profile/{id}
inside the page() function, then have profile/colin
and profile/matilda
both root to that page, and the id
is available to the ui & server.
from brochure.
Hey, Colin! Great work here with this module.
On this issue, let me know what you think about the direction below.
This first part would be called once, as part of a "compilation" step:
compile_route <- function(route) {
stopifnot(is.character(route) && length(route) == 1)
params <- stringr::str_match_all(route, "\\{(\\w+)\\}")[[1]][,2]
extractor <- stringr::str_replace_all(route, "\\{\\w+\\}", "([^//]+)")[[1]]
list(
template = route,
parse = function(path) {
parsed <- stringr::str_match_all(path, extractor)[[1]]
if (!nrow(parsed)) return(NULL)
setNames(parsed[1,-1], params)
}
)
}
route <- compile_route("/prefix/{arg1}/{arg2}-argsuffix/suffix")
And then in request time:
# NULL
route$parse("/blabla")
route$parse("/prefix")
route$parse("/prefix/1")
route$parse("/prefix/1/2-argsuffix")
route$parse("/prefix/1/almost/there-argsuffix/suffix")
# named vectors
route$parse("/prefix/1/2-argsuffix/suffix")
route$parse("/prefix/first/second with spaces-argsuffix/suffix")
Some timings, just for reference (8GB RAM, 2.7 GHz i7 CPU):
Unit: milliseconds
expr min lq
route$parse("/prefix/first/second with spaces-argsuffix/suffix") 0.01958 0.0199325
mean median uq max neval
0.020986522 0.0200675 0.0202895 0.117091 1000
Maybe this is missing some more validation in order to become user facing. I didn't test more weird inputs
from brochure.
Ok back to this.
Internally, express uses https://www.npmjs.com/package/path-to-regexp, so maybe we should have something in the same spirit, that turns path into regex, then does a grepl on the route table
from brochure.
Related Issues (20)
- adding a "www" folder to my app caused it to unexpectedly break HOT 5
- shinyashboard doesn't refresh page, it opens a new one HOT 2
- Deployment Help for Brochure application HOT 7
- test golem recommended don't work HOT 1
- Add test for default page
- reactLog error HOT 4
- wrapped should default to tagList in brochureApp HOT 1
- redirect() function injects "<script>$( document ).ready(function().." into body of bs4Dashh::dashboardPage() HOT 4
- Clarify the way brochureApp() handles `..`
- Css not recognized when adapting traditional golem app to brochure [solved]
- Creating a brochure app through golem does not import `{brochure}` HOT 2
- Brochure hex logo
- Strange EOF issue when POSTing JSON HOT 1
- Is there a need to use inner-session async in `brochure` pages?
- Page redirection fails for rstudio server HOT 2
- Brochure adds unnecessary container-fluid HOT 4
- Start from within RStudio
- feat: path should match based on regex
- bug: sub-path not working HOT 1
- Bootswatch-themes per page don't get applied
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brochure.