Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More documentation for Adding Context with Masonite #66

Open
tpow opened this issue Mar 31, 2023 · 0 comments
Open

More documentation for Adding Context with Masonite #66

tpow opened this issue Mar 31, 2023 · 0 comments

Comments

@tpow
Copy link

tpow commented Mar 31, 2023

The exceptionite readme documentation is quite helpful. Thanks!

However, I am using Masonite (v4) and it took me a bit to figure out a reasonable way to add an additional block to the context tab. The Adding Context section shows a handler, but I wasn't sure of the best way to get it in the Masonite context.

I ended up creating a new provider:

python craft provider ExceptioniteContextProvider

I then updated it to include the new block (shown here using the sample from the readme):

import sys

from exceptionite import Block                                                   
from masonite.providers import Provider
                                                                              
class ExceptioniteContextProvider(Provider):                                         
    def __init__(self, application):
        self.application = application

    def register(self):                                                          
        handler = self.application.make("exception_handler").get_driver("exceptionite")
        if handler:
            handler.renderer("web").tab("context").add_blocks(SystemVarsBlock)

    def boot(self):
        pass

class SystemVarsBlock(Block):
    id = "system_vars"
    name = "System Variables"
    icon = "LightBulbIcon"

    def build(self):
        return {
           "sys argv": sys.argv
        }

I then added it to Masonite's config/providers.py by updating the file:

...
from app.providers import ExceptioniteContextProvider

PROVIDERS = [
    ...
    ExceptioniteContextProvider,
]

This works, but I'd love to know if there's a better approach. Do I need to check for debug mode or otherwise make sure that exceptionite is being used? Ideally this could be deployed in a production environment without needing changes to disable it.

Should something like this be added to the documentation?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant