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

Make jinja2 env configurable #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jgsogo
Copy link

@jgsogo jgsogo commented Mar 7, 2024

Feature: VizFactory can take the jinja2 environment from outside (fallbacks to the same default it was before)

With this change, users can override the templates used for the different visualizers. Example:

import ontospy
from ontospy.gendocs.viz.viz_html_single import *
from ontospy.gendocs.jinja_env import add_default_filters
from jinja2 import Environment, PackageLoader, select_autoescape, ChoiceLoader

g = ontospy.Ontospy("http://cohere.open.ac.uk/ontology/cohere.owl#")

# Provide my jinja2 environment so I can override some templates
my_environment = Environment(
    loader=ChoiceLoader(
        [
            FileSystemLoader(["/override/templates"]),
            PackageLoader("ontospy.gendocs.media", "templates"),
        ]
    ),
    autoescape=select_autoescape(["html", "xml"]),
    extensions=["jinja2_time.TimeExtension"],
)
add_default_filters(my_environment)

v = HTMLVisualizer(g, jinja2env=my_environment) # => instantiate the visualization object
v.build() # => render visualization. You can pass an 'output_path' parameter too
v.preview() # => open in browser

Personal note.- I plan to use the gendocs capability (html_multi) for one of my projects (I really like the output!). I would like to contribute to the project. Besides the contributions I would love to do around the template framework, I can help updating the codebase (#129) or improving the testing.

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.

None yet

1 participant