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

feat: adds HTMXConfig for plugin customization #6

Merged
merged 2 commits into from
Oct 23, 2024
Merged

Conversation

cofin
Copy link
Member

@cofin cofin commented Oct 23, 2024

Description

Closes

Summary by Sourcery

Add HTMXConfig class to enable customization of the HTMX plugin, allowing users to configure whether the HTMXRequest class is set globally. Update HTMXPlugin to utilize this configuration and add corresponding tests to ensure correct behavior.

New Features:

  • Introduce HTMXConfig class to allow customization of the HTMX plugin.

Enhancements:

  • Modify HTMXPlugin to accept an optional HTMXConfig parameter for configuration.

Tests:

  • Add tests for HTMXPlugin to verify behavior of set_request_class_globally configuration.

Copy link

sourcery-ai bot commented Oct 23, 2024

Reviewer's Guide by Sourcery

This pull request introduces an HTMXConfig class for customizing the HTMX plugin behavior, particularly the ability to control whether the HTMXRequest class is set globally. It also adds new tests to verify the plugin's functionality with different configurations.

Sequence diagram for HTMXPlugin initialization and app configuration

sequenceDiagram
    participant User
    participant HTMXPlugin
    participant AppConfig
    User->>HTMXPlugin: Initialize with HTMXConfig
    HTMXPlugin->>HTMXConfig: Create default if none provided
    HTMXPlugin->>AppConfig: on_app_init(AppConfig)
    alt set_request_class_globally is True
        HTMXPlugin->>AppConfig: Set request_class to HTMXRequest
    else set_request_class_globally is False
        HTMXPlugin->>AppConfig: Keep request_class as None
    end
Loading

Class diagram for HTMXConfig and HTMXPlugin

classDiagram
    class HTMXConfig {
        bool set_request_class_globally
    }
    class HTMXPlugin {
        HTMXConfig _config
        +HTMXPlugin(HTMXConfig config)
        +HTMXConfig config()
        +AppConfig on_app_init(AppConfig app_config)
    }
    HTMXPlugin --> HTMXConfig
    note for HTMXConfig "Configuration for HTMX Plugin, including setting request class globally."
Loading

File-Level Changes

Change Details Files
Introduction of HTMXConfig class for plugin customization
  • Added HTMXConfig dataclass with a set_request_class_globally flag
  • Modified HTMXPlugin to accept an optional HTMXConfig instance
  • Updated HTMXPlugin to use the configuration for setting the request class
litestar_htmx/plugin.py
Updated HTMXPlugin initialization and behavior
  • Modified init method to accept an optional HTMXConfig
  • Added a config property to access the plugin configuration
  • Updated on_app_init method to respect the set_request_class_globally flag
litestar_htmx/plugin.py
Added new tests for HTMXPlugin functionality
  • Created test_htmx_plugin.py file with new tests
  • Added tests for different set_request_class_globally configurations
  • Included a test for not overriding an existing custom request class
tests/test_htmx_plugin.py
Updated package exports
  • Added HTMXConfig to the all list in init.py
litestar_htmx/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

@cofin cofin merged commit d1aa968 into main Oct 23, 2024
13 checks passed
@cofin cofin deleted the configurable_plugin branch October 23, 2024 17:25
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

Successfully merging this pull request may close these issues.

1 participant