Comments (12)
Thinking about it more I think I would prefer just a simple hash (or Route object) with url and method attributes. Maybe have two helpers, one that returns a route and one that just returns the path.
res.locals.routes # functions return Route object
res.locals.paths # functions return URLs as strings
//- form_helper.jade
mixin form(route)
form(action=route.url, method=route.method)
if block
block
//- link_helper.jade
mixin link(text, path)
a(href=path.url)
text
//- index.jade
+link(paths.users())
+form(routes.updateUser(123))
from exprestive.
I agree with @charlierudolph. Good to keep the paths as paths, but an abstraction over them which encapsulates the full action (path + method) would be useful.
from exprestive.
I like this, what do you guys want to do for restful routes then? I think both routes and paths should have the same name
from exprestive.
Please explain your last comment Alex. I'm unsure what you are referring to
from exprestive.
Sorry, I'm talking about update
, create
, and destroy
actions.
If we have separate routes object they can't be named the same as show
and index
because they have different methods.
Should paths contain a subset of the routes object since "user" and "update_user" would be the same path?
paths = { "user", "users", "new_user", "edit_user" }
routes = { "user", "users", "new_user", "edit_user", "update_user", "create_user", "destroy_user" }
from exprestive.
I would think paths and routes have the same keys but just different values. Thinking about routes added by something other then resources
I don't think its makes sense to restrict what goes into paths
from exprestive.
I get the first path (separate paths and methods), but not the second part (paths vs routes). Can somebody please lay this out more simply, with examples? The solution that the conversation ended with here seems redundant, where routes are just a superset of paths.
from exprestive.
This is the current proposal
paths.editUser(123) # "/users/123/edit"
routes.editUser(123).url # "/users/123/edit"
routes.editUser(123).method # "GET"
from exprestive.
I don't like the duplication between paths.foo
and routes.foo.url
Can we go with just the routes
version for now, and then introduce a shortcut syntax for paths later as needed? We could also override the toString
method on the object returned by routes.foo
, so that it returns the url. This allows it to be used directly for the path in templates (which call toString
on objects).
<form action="<%= routes.editUser(123) %>"
from exprestive.
This was the original idea for this PR. The difference between using a non-primitive string and setting the toString
method on an object is non primitive strings also set valueOf
, length
, and all String
prototype methods such as slice
, etc...
from exprestive.
Non-primitive strings sounds like the way to go to me then. routes
seems a better namespace for that, since this comes from the routes file.
from exprestive.
Merged in c1338d83
from exprestive.
Related Issues (12)
- Use verbatim routes files HOT 4
- Better errors
- Support for _method HOT 1
- res.locals.routes is not set in controller actions HOT 1
- Support for scopes HOT 1
- Access reverse routes from this.routes from controllers HOT 5
- Idea: make controllers simple functions HOT 4
- Set @routes in middleware functions HOT 2
- Use simple *.js files. HOT 2
- adding middleware on a per-scope basis HOT 2
- support es6
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 exprestive.