Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Refactor fishbowl to use jinja #1018

Closed
t92549 opened this issue Jul 29, 2022 · 2 comments · Fixed by #1034
Closed

Refactor fishbowl to use jinja #1018

t92549 opened this issue Jul 29, 2022 · 2 comments · Fixed by #1034

Comments

@t92549
Copy link
Contributor

t92549 commented Jul 29, 2022

jinja is a template engine for Python. It could be used to make the fishbowl code clearer, more extensible and maintainable.

@t92549
Copy link
Contributor Author

t92549 commented Jul 29, 2022

Example usage of jinja:

from jinja2.nativetypes import NativeEnvironment
env = NativeEnvironment()

def capitalize(input):
    return input.capitalize()

function_dict = {
    "capitalize": capitalize
}

t = env.from_string("def __init__(self, {% for input in inputs %}{{ capitalize(input) }}=None, {% endfor %}options=None):")
t.globals.update(function_dict)
print(t.render(inputs=["input", "skip", "validate"]))
'def __init__(self, Input=None, Skip=None, Validate=None, options=None):'

The capitalize function is just there to show how custom functions work. In real usage, I think a different Environment would be used, and you would use a template file rather than a string.

@t92549 t92549 modified the milestones: v2_backlog, v2.0.0 Aug 11, 2022
@t92549 t92549 self-assigned this Oct 17, 2022
@t92549 t92549 linked a pull request Nov 7, 2022 that will close this issue
@t92549
Copy link
Contributor Author

t92549 commented Nov 7, 2022

Closed by #1034

@t92549 t92549 closed this as completed Nov 7, 2022
@t92549 t92549 modified the milestones: v2.0.0, v2.0.0-alpha-0.4 Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant