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

Jinja keys #132

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Jinja keys #132

wants to merge 3 commits into from

Conversation

redhog
Copy link
Collaborator

@redhog redhog commented Oct 29, 2024

Closes #85

API for operations writers:

    def evaluate_expression(self, config_path, default_expression=None, default_value=None, **context):
        """Evaluates a jinja2 expression specified in the operation
        config (or a default expression if not found) against a given
        context.

        config_path is itself a jinja2 expression, evaluated within
        the context of the operation config (self.config) and one
        additional variable: config, which is bound to the entire
        config file.

        Evaluating config_path should yield a jinja2 expression, or
        alternatively a list of expressions (if so, a list of values
        is returned).

        If no expression is found and no default expression is
        provided, or the expression evaluates to Undefined,
        default_value is returned.

        Example:

        Assuming
        
          config_path = "input.title_keys"
          self.config = {"input": {"title_keys": ["title", "categories.0.title"]}}
          context = {"input": {"title": "Hello", "categories": [{"title": "world"}]}}

        this function will return ["Hello", "world"].

        """
    def evaluate_template(self, config_path, default_template=None, **context):
        """Renders a jinja2 template specified in the operation config
        (or a default template if not found) against a given context.

        config_path is a jinja2 expression, evaluated within
        the context of the operation config (self.config) and one
        additional variable: config, which is bound to the entire
        config file.
        """

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.

Consistent variable syntax / allowing using deeply nested data as keys
1 participant