diff --git a/README.md b/README.md index 4f8d650..ce914e1 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,15 @@ You can find the legacy Inertia PingCRM demo with Masonite here [demo](https://g ## Features -- _Add your package main features here_ -- _and here_ +Almost all features of the official server-side adapters are present 😃 + +- Shared data +- Partial reloads +- Lazy loaded props +- Set root view in a provider +- Set root view per view +- Enable sharing Masonite routes (prefer using [masonite-js-routes](https://github.com/girardinsamuel/masonite-js-routes)) +- Enable sharing Masonite flash messages ## Official Masonite Documentation diff --git a/app/http/controllers/InertiaController.py b/app/http/controllers/InertiaController.py index 9cf9618..5282ef1 100644 --- a/app/http/controllers/InertiaController.py +++ b/app/http/controllers/InertiaController.py @@ -1,9 +1,10 @@ """Inertia Demo Controller""" from masonite.controllers import Controller -from masonite.inertia import InertiaResponse from masonite.view import View from masonite.request import Request +from masonite.inertia import InertiaResponse + class InertiaController(Controller): """Controller for testing Inertia.""" @@ -22,6 +23,4 @@ def inertia_with_error(self, view: InertiaResponse, request: Request): return request.redirect("/") def helloworld(self, view: InertiaResponse): - return view.render("HelloWorld", {"first_name": "Sam"}).with_root_view( - "spa_view_2" - ) + return view.render("HelloWorld", {"first_name": "Sam"}, "spa_view_2") diff --git a/config/inertia.py b/config/inertia.py index d402572..e679dfa 100644 --- a/config/inertia.py +++ b/config/inertia.py @@ -6,8 +6,52 @@ | Mix Manifest |-------------------------------------------------------------------------- | -| Absolute path to mix-manifest.json location +| Absolute path to mix-manifest.json location. It's needed for computing +| js assets version. | +| default: root directory """ PUBLIC_PATH = os.getcwd() + + +""" +|-------------------------------------------------------------------------- +| Root view +|-------------------------------------------------------------------------- +| +| Root template view used by your Inertia Controllers to render the page. +| This is the name of the view without .html. This can also be overriden with +| set_root_view Inertia helper. +| +| default: app +""" + +ROOT_VIEW = "spa_view" + +""" +|-------------------------------------------------------------------------- +| Include routes +|-------------------------------------------------------------------------- +| +| Include server-side routes as JSON payload in Inertia response (props) +| Might be needed if you're not using masonite-js-routes. You can also do +| it yourself with Inertia share helper. +| +| default: False +""" + +INCLUDE_ROUTES = False + +""" +|-------------------------------------------------------------------------- +| Share flash message +|-------------------------------------------------------------------------- +| +| Include flash messages as JSON payload in Inertia response (props) +| You can also do it yourself with Inertia share helper. +| +| default: True +""" + +INCLUDE_FLASH_MESSAGES = True diff --git a/resources/templates/spa_view_2.html b/resources/templates/spa_view_2.html index b3400ff..32815da 100644 --- a/resources/templates/spa_view_2.html +++ b/resources/templates/spa_view_2.html @@ -6,7 +6,6 @@ Inertia SPA - diff --git a/src/masonite/inertia/core/InertiaResponse.py b/src/masonite/inertia/core/InertiaResponse.py index 468fa1c..2d7debb 100644 --- a/src/masonite/inertia/core/InertiaResponse.py +++ b/src/masonite/inertia/core/InertiaResponse.py @@ -31,10 +31,6 @@ def __init__(self, container): def set_root_view(self, root_view): self.root_view = root_view - def with_root_view(self, root_view): - self.root_view = root_view - return self - def _load_routes(self): from routes.web import ROUTES @@ -43,7 +39,7 @@ def _load_routes(self): if route.named_route: self.routes.update({route.named_route: route.route_url}) - def render(self, component, props={}): + def render(self, component, props={}, custom_root_view=None): page_data = self.get_page_data(component, props) if self.request.is_inertia: @@ -51,7 +47,8 @@ def render(self, component, props={}): return self self.rendered_template = self.view( - self.root_view, {"page": html.escape(json.dumps(page_data))} + custom_root_view if custom_root_view else self.root_view, + {"page": html.escape(json.dumps(page_data))}, ).rendered_template return self diff --git a/storage/static/js/app.js b/storage/static/js/app.js index b8b0bf4..1024328 100644 --- a/storage/static/js/app.js +++ b/storage/static/js/app.js @@ -3,19 +3,19 @@ import { InertiaApp } from "@inertiajs/inertia-vue"; import route from "ziggy-js"; // import { Ziggy } from "./ziggy"; -Vue.mixin({ - methods: { - route: (name, params, absolute) => - route(name, params, absolute, window.Ziggy), - }, -}); +// Vue.mixin({ +// methods: { +// route: (name, params, absolute) => +// route(name, params, absolute, window.Ziggy), +// }, +// }); +// OR +// Vue.prototype.$route = (...args) => route(...args).url(); Vue.use(InertiaApp); const app = document.getElementById("app"); -// Vue.prototype.$route = (...args) => route(...args).url(); - new Vue({ render: (h) => h(InertiaApp, { diff --git a/storage/static/js/pages/HelloWorld.vue b/storage/static/js/pages/HelloWorld.vue index cede656..4b65226 100644 --- a/storage/static/js/pages/HelloWorld.vue +++ b/storage/static/js/pages/HelloWorld.vue @@ -2,7 +2,6 @@

Hello World {{ first_name }}

< Go back -

Current route: {{ route().current() }}