Skip to main content

PyRoutesJS provide a Javascript routes generation function like Python Routes Mapper.generate method

Project description

PyRoutesJS provide a Javascript routes generation function like Python Routes Mapper.generate method.

Introduction

  • Do you use Python Routes library in Pylons or other applications ?

  • Do you use something like ${h.url('entry_view', entry_id=2)} in your templates ?

So, now do you dream to have Javascript routes generation function ?

PyRoutesJS is the tool that you need !

If you have this Routes Mapper configuration :

...
map = Mapper()
...
map.connect('entry_view', '/entries/{issue_id:\d*}/', controller='issues', action='view')
map.connect('entry_edit', '/entries/{issue_id:\d*}/edit', controller='issues', action='edit')
...

In your javascript files, you can use PyRoutesJS like this :

pyroutes.generate('entry_view', entry_id=2); // return '/entries/1/'
pyroutes.generate('entry_edit', entry_id=5); // return '/entries/5/edit/'

Installation

$ pip install pyroutes.js

Pylons integration

In my_app/config/middleware.py file, append :

...
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware

...

from pyroutesjs import Middleware as PyRoutesJSMiddleware       # <= append this line

...

from my_app.config.environment import load_environment

...

def make_app(global_conf, full_stack=True, static_files=True, **app_conf):

    ...

    # Append PyRoutes.js middleware
    app = PyRoutesJSMiddleware(app, config['routes.map'])      # <= append this line

    app.config = config
    return app

In your template, append :

<script type="text/javascript" src="${h.url('/js/pyroutes.js')}"></script>

Limitations

  • Currently you can only generate named routes

Source code

Mercurial repository is here : https://bitbucket.org/harobed/pyroutes.js/src

You can clone the code :

$ hg clone http://bitbucket.org/harobed/pyroutes.js

Issue tracker

You can report your bugs here : https://bitbucket.org/harobed/pyroutes.js/issues

News

0.1.0 (not released)

  • Initial version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyroutes.js-0.1.0dev1.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file pyroutes.js-0.1.0dev1.tar.gz.

File metadata

File hashes

Hashes for pyroutes.js-0.1.0dev1.tar.gz
Algorithm Hash digest
SHA256 05fae283a293f37f653e663e3589e8eed5dddacfdfbfb5bff0deda0870293eac
MD5 32278a8f7576214a5ee0b3f2bf47cacb
BLAKE2b-256 b9843333c8ceb605004c8f56e4778f1e491cc28dd3d858a1925f0588d1d64db4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page