Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supporting subroute #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

supporting subroute #7

wants to merge 1 commit into from

Conversation

aodag
Copy link

@aodag aodag commented Jun 28, 2011

directive to register nested routes.

Example::

 add_route('hamm', '/hamm')
 add_subroute('hamm', 'egg', '{var}/egg')

mapping results::

 route_path('hamm', request) => /hamm
 route_path('egg', request, var='spam') => /hamm/spam/egg

@mcdonc
Copy link
Member

mcdonc commented Jun 29, 2011

This is a nice idea.

How about something like this as a pattern in Pyramid itself:

# in pyramid

class Configurator(object):
    def with_root_route(self, route_name):
        if not self.routes_mapper.has_route(route_name):
            raise ConfigurationError
        configurator = self.__class__(registry=self.registry,
                                      package=self.package,
                                      autocommit=self.autocommit)
        configurator.root_route_name = route_name
        return configurator

    def mount(self, function, route_name):
        function = self.maybe_dotted(function)
        config = self.with_root_route(route_name)
        function(config)

    def add_route(self, *arg, **kw):
        # .. do what add_route currently does now but taking into account
        # that there might be a root_route_name in effect on self (ie. it
        # would do what your current add_subroute does in that case) ...

# in "master" package

if __name__ == '__main__':
    config = Configurator()
    config.add_route('sub', '/sub')
    config.mount('otherpkg.subapp', 'sub')

# in "otherpkg" package:

def subapp(config):
    config.add_route('hello', '/hello')
    # would actually register as '/sub/hello' when called via "mount"

@aodag
Copy link
Author

aodag commented Jun 29, 2011

It's nice to improve modulability with routes.
I wanna contribute to that feature for subapplication mounting.

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.

2 participants