Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[bz5600383] Generate URLs based on dynamic urls with regex and wildcards does not work #159

Closed
redonkulus opened this Issue May 23, 2012 · 7 comments

Comments

Projects
None yet
4 participants
Contributor

redonkulus commented May 23, 2012

I'm trying to generate URLs based on dynamic urls with regex and wildcards, here's part of the routes.json:

"story": {
"verbs": ["get"],
"path" : "/:interestId/:alias",
"regex": {"alias": "?:(.+).html."},
"call": "page.index",
"params": "alias_type=story"
},
"interest_id": {
"verbs": ["get"],
"path" : "/:interestId",
"regex": {"interestId": "?:([^/]
)/?"},
"call": "page.index",
"params": "alias_type=path&alias=/"
},
"path" : {
"verbs" : ["get"],
"path" : "*",
"call" : "page.index",
"params": "alias_type=path"
}

If I call, url.make('page', 'index', { interestId: 'Barack_Obama' }), it will
render : *?interestId=Barack_Obama

If I call, url.make('page', 'index', '', 'GET', { interestId: 'Barack_Obama'
}), it will render : *?interestId=Barack_Obama

So a couple things are wrong with this:

  • It just matches the last path in the routes.json.
  • It doesn't generate a useful URL
Collaborator

mridgway commented May 25, 2012

It feels wrong for URLs to be based off of Mojit instances and actions. It should be based off of the routes.json, using the identifiers that are used there.

@rwaldura rwaldura closed this Feb 21, 2013

Contributor

redonkulus commented Feb 21, 2013

@rwaldura why was this closed? Its a bug. In my examples above, the URL I want is never actually rendered correctly.

Contributor

rwaldura commented Feb 21, 2013

Why are you trying to generate URLs based on dynamic urls with regex and wildcards?
What's the use-case?

Contributor

redonkulus commented Feb 21, 2013

@rwaldura I'm passing in a variable to url.make() so that the URL is generated dynamically. Based on the route the following:

url.make('page', 'index', '', 'GET', { interestId: 'Barack_Obama'});

Should produce /Barack_Obama

However, the 3rd rule always matches since all the routes share the same controller/action call. We should be able to use the same controller/action call for different routes. As Mike said, it should match based on the routes and not just the "call" attribute.

Collaborator

caridy commented Feb 22, 2013

-1

This might be VERY problematic.

Contributor

redonkulus commented Feb 22, 2013

@caridy are you saying the above pattern would not be recommended in the routes file? I would have to have a different action to support each route? Seems convoluted.

Collaborator

caridy commented Feb 22, 2013

I'm saying we need a better way to define routes. Here is what I will like to see:

1- a way to identify routes
2- using the route identifier from mojits and from shared mojits controller to produce urls
3- using the route identifier from a template's helper in the client and server to produce urls

After few weeks analyzing this problem as part of a separate effort (YAF integration), I came to the conclusion that such identifier is, in most cases, what we also call an app-level event, hence number 2 is potentially problematic because of the nature of the mojits, specifically the share-ability, which makes difficult to have app-level stuff that will be triggered by a shareable piece.

Bottomline, if we consider the "call" that identifier in the current mojito infrastructure, you should move part of the logic into specs by having instances of your top level mojito (your current "index"), having custom default actions per each. In which you might ended up with a 1-1 mapping between routes and mojit instances. Here is an example:

{
    "story": {
        "verbs": ["get"],
        "path": "/:interestId/:alias",
        "regex": {
            "alias": "?:(.+).html.*"
        },
        "call": "page-story.index",
        "params": "alias_type=story"
    },
    "interest_id": {
        "verbs": ["get"],
        "path": "/:interestId",
        "regex": {
            "interestId": "?:([^/]*)/?"
        },
        "call": "page-interest.index",
        "params": "alias_type=path&alias=/"
    },
    "path": {
        "verbs": ["get"],
        "path": "*",
        "call": "page.index",
        "params": "alias_type=path"
    }
}

then in your specs:

{
    "specs": {
        "index": {
            "type": "YourAwesomeFrame",
            "action": "index",
            "config": {
                "something": "here"
            }
        },
        "page-story": {
            "base": "page"
        },
        "page-inderest": {
            "base": "page"
        }
    }
}

In which case you can even move those params into the instance in specs, and just call for urls based on the instance name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment