Skip to main content

Yet Another Expansion Syntax (pronounced 'Yasssss Kweeeeen')

Project description

Yet Another Expansion Syntax (pronounced ‘Yasssss Kweeeeen’) for expanding complex data (YAML / JSON) with Jinja2 templating

If a block has no control keywords, everything is emitted as is:

import yaes

block = {
    "ya": "{{ a }}"
}

values = {
    "a": "sure"
}

list(yaes.each(block, values))
# [
#     ({"ya": "{{ a }}"}, {"a": "sure"})
# ]

The behavior is the same if you send a list of blocks:

list(yaes.each([block], values))
# [
#     ({"ya": "{{ a }}"}, {"a": "sure"})
# ]

requires

If a requires keyword is present, all the keys listed must be in values for the block to emitted:

blocks = [
    {
        "name": "one",
        "requires": "a"
    },
    {
        "name": "twp",
        "requires": ["a", "b"]
    }
]

values = {
    "a": "sure"
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": "sure"})
# ]

This is useful for modules like opengui, where we don’t want to evaluate the conditions on some fields unless other fields in those conditions actually have values.

transpose

If a transpose keyword is present, it’ll use the key pairs to transpose the values:

blocks = [
    {
        "name": "one",
        "transpose": {
            "b": "a"
        }
    }
]

values = {
    "a": "sure"
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": "sure", "b": "sure"})
# ]

This is useful if you’re re-using a template that uses veriables and you want to replace them with your usage’s specific variables.

iterate

If a iterate keyword is present, it’ll use the key pairs to iterate new values:

blocks = [
    {
        "name": "{{ fruit }}",
        "iterate": {
            "fruit": "fruits"
        }
    }
]

values = {
    "fruits": [
        "apple",
        "pear",
        "orange"
    ]
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "apple",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     ),
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "pear",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     ),
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "orange",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     )
# ]

This is useful with opengui as you can take the values of a multi option field and use those values to create a new field for each option selected.

condition

If a condition keyword is present, it’ll only emit the block if the condition evaluates True:

blocks = [
    {
        "name": "one",
        "condition": "{? a == 1 ?}"
    },
    {
        "name": "two",
        "condition": "{? a == 2 ?}"
    }
]

values = {
    "a": 1
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": 1})
# ]

This is useful if you only want to use a block under certain conditions.

blocks

If a blocks keyword is present, it’ll expand those blocks, using the parent block as a base:

blocks = [
    {
        "base": "value",
        "blocks": [
            {
                "name": "one"
            },
            {
                "name": "two",
                "base": "override"
            }
        ]
    }
]

values = {
    "a": 1
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "base": "value",
#             "name": "one"
#         },
#         {
#             "a": 1
#         }
#     ),
#     (
#         {
#             "base": "override",
#             "name": "two"
#         },
#         {
#             "a": 1
#         }
#     )
# ]

This is useful if you have a condition or iterate that you want to apply to multiple block without having to use those keywords on each block.

values

If a values keyword is present, it’ll merge those values into teh values emitted:

blocks = [
    {
        "name": "one"
    },
    {
        "name": "two",
        "values": {
            "a": 2,
            "c": "{{ b }}sah"
        }
    }
]

values = {
    "a": 1,
    "b": "yes"
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "name": "one"
#         },
#         {
#             "a": 1,
#             "b": "yes"
#         }
#     ),
#     (
#         {
#             "name": "two"
#         },
#         {
#             "a": 2,
#             "b": "yes",
#             "c": "yessah"
#         }
#     )
# ]

This is useful if you want to override the existing values but at this point I don’t think even I’ve ever used it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaes-0.2.5.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaes-0.2.5-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file yaes-0.2.5.tar.gz.

File metadata

  • Download URL: yaes-0.2.5.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for yaes-0.2.5.tar.gz
Algorithm Hash digest
SHA256 74855bffed08c4a018495f8041a0f77f5f9e29bde74f768e8f35a02a51d547b4
MD5 68ddf007047c8ff28610974b14733077
BLAKE2b-256 1d658f538190eb99a6954d1d88da967f20b548d29b95cd3ab284f957885d039b

See more details on using hashes here.

File details

Details for the file yaes-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: yaes-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for yaes-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6fe41669eb198f733a73b59e8d615881feb23bcb46e427f27b34018d377d307f
MD5 98a8709c56d6dc8ab4a7d29d88ba4864
BLAKE2b-256 62a0c80ed6ad2b0128f43d2d720cda0dbdba5677ccffa4b15a433856e0ce31ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page