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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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