Skip to main content

Use your Masonite named routes in Javascript

Project description

Masonite JS Routes

Masonite Package GitHub Workflow Status (branch) Coveralls github branch PyPI Python Version GitHub release (latest by date) License Code style: black

Introduction

Use your Masonite named routes in Javascript !

This package creates a helper that you can include in your views. It will export a JavaScript object of your application's named routes, keyed by their names (aliases).

You can combine it with ziggy-js library as to get a global route() helper function which you can use to access your routes in your JavaScript.

Features

  • Add your package main features here
  • and here

Official Masonite Documentation

New to Masonite ? Please first read the Official Documentation. Masonite strives to have extremely comprehensive documentation 😃. It would be wise to go through the tutorials there. If you find any discrepencies or anything that doesn't make sense, be sure to comment directly on the documentation to start a discussion!

Also be sure to join the Slack channel!

Installation

pip install masonite-js-routes

Configuration

Add JSRoutesProvider to your project in config/providers.py:

# config/providers.py
# ...
from masonite.js_routes import JSRoutesProvider

# ...
PROVIDERS = [
    # ...

    # Third Party Providers
    JSRoutesProvider,

    # ...
]

You can skip this step if you don't want to filters routes included by the helper. Else you must publish the config file by running the command:

python craft js_routes:install

Then you should have a new js_routes.py config file in config/.

python craft js_routes:install

Usage

In your views, just add this helper where you want to get Ziggy routes as a Javascript object:

{{ js_routes() }}

Basic filtering

Only the routes matching a list of name patterns will be included:

FILTERS = {
    "only": ["welcome.*"],
}

Only the routes which does not match a list of name patterns will be included:

FILTERS = {
    "except": ["admin.*"],
}

Note: You have to choose one or the other. Setting both only and except will disable filtering altogether and simply return the default list of routes.

Filtering using Groups

Only the routes matching a group or a list of groups will be included if groups are passed to the helpers

FILTERS = {
    "groups": {
        "app": ["app.*"],
        "api": ["api.*"],
    }
}

and in your view :

{{ js_routes('app') }}

or a list of group names

{{ js_routes(['app', 'api']) }}

Note: Passing group names to the routes helper will always take precedence over your other only or except settings.

Content Security Policy

A Content Security Policy may block unsafe inline scripts which Ziggy uses to pass the routes to JavaScript. By adding a nonce to your CSP you can allow certain inlined scripts. To add this nonce to Ziggy you can pass it as the second argument to the helper:

{{ routes(false, '[YOUR_NONCE]') }}

Contributing

Please read the Contributing Documentation here.

License

Masonite JS Routes is open-sourced software licensed under the MIT license.

Disclaimer: this package is based on the Laravel package Ziggy.

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

masonite-js-routes-0.2.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

masonite_js_routes-0.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file masonite-js-routes-0.2.0.tar.gz.

File metadata

  • Download URL: masonite-js-routes-0.2.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for masonite-js-routes-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5f5fd9fcb9fa76f1275f0e1529a35083188b522b261c838e6c5fd7e7de9615b5
MD5 49a418777d04955df136b4ec56b003de
BLAKE2b-256 96a1d6615ed747ba25f47168efcca7871fda2afa45b8dbcede9d2b7fe8893939

See more details on using hashes here.

File details

Details for the file masonite_js_routes-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: masonite_js_routes-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for masonite_js_routes-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a02d31e23340c1a09cc6a139894878e1acb237dd95afdcc12e3b5bb7413bf984
MD5 888d3058016c2fab6e9286f4d8c0821d
BLAKE2b-256 179adfbe4d7534a793aa958aaa1fbae8ef7a1de856bb41c1748dae1a01e3cecc

See more details on using hashes here.

Supported by

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