Skip to content

added automatic url_rule generation in route()-decorator#92

Open
dersphere wants to merge 1 commit intojbeluch:developfrom
dersphere:auto_route
Open

added automatic url_rule generation in route()-decorator#92
dersphere wants to merge 1 commit intojbeluch:developfrom
dersphere:auto_route

Conversation

@dersphere
Copy link
Contributor

I'm not sure if this is something you/we really want, so I only updated the code. If you like it, I can add tests and update the docs.

With this change the following is possible:

@plugin.route(is_root=True)
def root():
    items = [
        {'label': 'Latest',
         'path': plugin.url_for('show_movies')},
    ]
    return plugin.finish(items)

@plugin.route()
def show_movies():
    items = [{
        'label': movie['title'],
        'is_playable': True,
        'path': plugin.url_for(
            endpoint='play_movie',
            movie_id=movie['id']
        )
    } for movie in get_movies()]
    return plugin.finish(items)

@plugin.route()
def func_with_much_params(foo, bar, lorem, ipsum):
    pass

@plugin.route()
def play_movie(movie_id):
    url = get_url(movie_id)
    return plugin.set_resolved_url(url)

The URLs from the above example will be:

'/'
'/show_movies'
'/func_with_much_params/foo/<foo>/bar/<bar>/lorem/<lorem>/ipsum/<ipsum>'
'/play_movie/movie_id/<movie_id>'

It could also be changed to not add the param name, example:

'/'
'/show_movies'
'/func_with_much_params/<foo>/<bar>/<lorem>/<ipsum>'
'/play_movie/<movie_id>'

This change should be fully backward compatible.
Personally I prefer defining the routes myself but while in development it saves some time. ;-)

@dersphere
Copy link
Contributor Author

What about this? Is this something you consider for xbmcswift?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant