Skip to content

Commit

Permalink
Use new handy PackageProvider to scaffold this package (#77)
Browse files Browse the repository at this point in the history
* update provider to use new feature

* update tests

* update readme

* remove old install command

* update makefile

* update install section in doc
  • Loading branch information
girardinsamuel authored Nov 1, 2021
1 parent a396a08 commit 9ea0a16
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 148 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ class AppHttpKernel(HttpKernel):
Make sure that this middleware is added before the EncryptCookies middleware else you will get
some issues with CSRF token validation as `XSRF-TOKEN` value won't be encrypted.

Finally publish the package configuration (to get `config/inertia.py`) to your project:
Finally if you want to change some parameters you can publish the package configuration file in your project:

```bash
python craft install:inertia
python craft package:publish inertia
```

Congratulations! You have now setup Inertia in your project! For more information on how to use Inertia.js got to its [documentation](https://inertiajs.com/installation).
Expand Down
15 changes: 10 additions & 5 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Requirements

* a Masonite 4 project
* a Node.js environment
- a Masonite 4 project
- a Node.js environment

## Installation

Expand All @@ -20,6 +20,7 @@ pip install masonite-inertia
Add `InertiaProvider` to your project

{% code title="config/providers.py" %}

```python
# ...
from masonite.inertia import InertiaProvider
Expand All @@ -31,6 +32,7 @@ PROVIDERS = [
InertiaProvider,
]
```

{% endcode %}

Add the Inertia middleware to your project
Expand All @@ -47,6 +49,7 @@ It's important to put this middleware before the `EncryptCookies` middleware !
{% endhint %}

{% code title="config/middleware.py" %}

```python
# ...
http_middleware = [
Expand All @@ -55,14 +58,16 @@ http_middleware = [
EncryptCookies
]
```

{% endcode %}

Finally publish the package configuration file to your project
Finally you can (optionally) publish the package configuration file to your project if you want to
change some configuration parameters:

```python
python craft install:inertia
python craft package:publish inertia
```

You should now have a configuration file `config/inertia.py`.
You should now have a configuration file `inertia.py` in your project configuration folder.

You're ready to start working with Inertia !
9 changes: 2 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ init: ## Install package dependencies
pip install --upgrade pip
# install test project and package dependencies
pip install -r requirements.txt
# install package
pip install .
# install dev dependencies (see setup.py)
pip install 'masonite-inertia[test,dev]'
# force correct version of cleo for tests for now
pip install cleo==0.8.1

# install package and dev dependencies
pip install '.[test,dev]'
test: ## Run package tests
python -m pytest tests
ci: ## [CI] Run package tests and lint
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"masonite.inertia.config",
"masonite.inertia.providers",
"masonite.inertia.middleware",
"masonite.inertia.commands",
"masonite.inertia.core",
"masonite.inertia.testing",
],
Expand Down
86 changes: 0 additions & 86 deletions src/masonite/inertia/commands/DemoCommand.py

This file was deleted.

27 changes: 0 additions & 27 deletions src/masonite/inertia/commands/InstallCommand.py

This file was deleted.

Empty file.
25 changes: 8 additions & 17 deletions src/masonite/inertia/providers/InertiaProvider.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
"""A InertiaProvider Service Provider."""
import os

from masonite.configuration import config
from masonite.facades import Config
from masonite.providers import Provider
from masonite.packages.providers import PackageProvider

from ..commands.DemoCommand import DemoCommand
from ..commands.InstallCommand import InstallCommand
from ..core.Inertia import Inertia
from ..helpers import inertia
from ..testing import InertiaTestingResponse

package_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


class InertiaProvider(Provider):
class InertiaProvider(PackageProvider):
"""Masonite adapter for Inertia.js Service Provider."""

def __init__(self, application):
self.application = application

def register(self):
# Config.merge_with("inertia", os.path.join(package_root, "config/inertia.py"))
Config.merge_with("inertia", "masonite.inertia.config.inertia")
def configure(self):
(
self.root("src/masonite/inertia")
.name("inertia")
.config("config/inertia.py", publish=True)
)
inertia = Inertia(self.application, config("inertia"))
self.application.bind("inertia", inertia)

self.application.make("commands").add(InstallCommand(), DemoCommand())
self.application.make("tests.response").add(InertiaTestingResponse)

def boot(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/config/providers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from masonite.notification.providers import NotificationProvider
from masonite.providers import (
AuthenticationProvider,
AuthorizationProvider,
BroadcastProvider,
CacheProvider,
EventProvider,
Expand Down Expand Up @@ -38,6 +39,7 @@
BroadcastProvider,
HashServiceProvider,
AuthenticationProvider,
AuthorizationProvider,
ValidationProvider,
InertiaProvider,
]
9 changes: 6 additions & 3 deletions tests/unit/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os

from masonite.tests import TestCase


class TestCommands(TestCase):
def test_install(self):
def test_publish_config(self):
(
self.craft("install:inertia")
self.craft("package:publish", "inertia")
.assertSuccess()
.assertOutputContains("Configuration File Created!")
.assertOutputContains("Config")
.assertOutputContains("tests/integrations/config/inertia.py")
)
assert os.path.isfile("tests/integrations/config/inertia.py")
os.remove("tests/integrations/config/inertia.py")

0 comments on commit 9ea0a16

Please sign in to comment.