-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pluggy | ||
|
||
hookimpl = pluggy.HookimplMarker("conditions") | ||
|
||
@hookimpl | ||
def register_operators(): | ||
def starts_with(_, text, prefix): | ||
return text.lower().startswith(prefix.lower()) | ||
|
||
def ends_with(_, text, suffix): | ||
return text.lower().endswith(suffix.lower()) | ||
|
||
return { | ||
"starts_with": starts_with, | ||
"ends_with": ends_with | ||
} | ||
|
||
@hookimpl | ||
def register_operator_choices(): | ||
return [ | ||
("starts_with", "Text Starts With"), | ||
("ends_with", "Text Ends With"), | ||
] | ||
|
||
@hookimpl | ||
def register_field_choices(): | ||
return [ | ||
("meta_description", "Meta Description"), | ||
("meta_keywords", "Meta Keywords"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pluggy | ||
|
||
# Define `pluggy` hookspecs (Specifications for Plugins) | ||
hookspec = pluggy.HookspecMarker("conditions") | ||
hookimpl = pluggy.HookimplMarker("conditions") | ||
|
||
|
||
class ConditionsSpec: | ||
"""Hook specifications for extending JSON Logic conditions.""" | ||
|
||
@hookspec | ||
def register_operators(): | ||
"""Return a dictionary of new JSON Logic operators.""" | ||
pass | ||
|
||
@hookspec | ||
def register_operator_choices(): | ||
"""Return a list of new operator choices.""" | ||
pass | ||
|
||
@hookspec | ||
def register_field_choices(): | ||
"""Return a list of new field choices.""" | ||
pass | ||
|
||
|
||
# ✅ Set up `pluggy` Plugin Manager | ||
plugin_manager = pluggy.PluginManager("conditions") | ||
plugin_manager.add_hookspecs(ConditionsSpec) | ||
|
||
# Discover installed plugins | ||
plugin_manager.load_setuptools_entrypoints("conditions") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters