Giter Site home page Giter Site logo

Comments (12)

charlierudolph avatar charlierudolph commented on July 26, 2024

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.

catharinejm avatar catharinejm commented on July 26, 2024

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.

alexdavid avatar alexdavid commented on July 26, 2024

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.

charlierudolph avatar charlierudolph commented on July 26, 2024

Please explain your last comment Alex. I'm unsure what you are referring to

from exprestive.

alexdavid avatar alexdavid commented on July 26, 2024

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.

charlierudolph avatar charlierudolph commented on July 26, 2024

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.

kevgo avatar kevgo commented on July 26, 2024

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.

alexdavid avatar alexdavid commented on July 26, 2024

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.

kevgo avatar kevgo commented on July 26, 2024

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.

alexdavid avatar alexdavid commented on July 26, 2024

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.

kevgo avatar kevgo commented on July 26, 2024

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.

alexdavid avatar alexdavid commented on July 26, 2024

Merged in c1338d83

from exprestive.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.