yaes
====
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"})
# ]
.. note::
requires can be a str or list of str.
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"})
# ]
.. note::
you can have multiple values to transpose
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"
# ]
# }
# )
# ]
.. note::
you can have multiple values to iterate, and it'll iterate over the different
pairs alphabetically by key
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})
# ]
.. note::
make sure you use '{?' and '?}' in the condition so it renders as a boolean.
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
# }
# )
# ]
.. note::
blocks within blocks with control keywords will have those keywords evaluated
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"
# }
# )
# ]
.. note::
you can have multiple pairs in values
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.
Raw data
{
"_id": null,
"home_page": "https://yaes.readthedocs.io/en/0.2.5/",
"name": "yaes",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Gaffer Fitch",
"author_email": "yaes@gaf3.com",
"download_url": "https://files.pythonhosted.org/packages/1d/65/8f538190eb99a6954d1d88da967f20b548d29b95cd3ab284f957885d039b/yaes-0.2.5.tar.gz",
"platform": null,
"description": "yaes\n====\n\nYet Another Expansion Syntax (pronounced 'Yasssss Kweeeeen') for expanding complex data (YAML / JSON) with Jinja2 templating\n\nIf a block has no control keywords, everything is emitted as is::\n\n import yaes\n\n block = {\n \"ya\": \"{{ a }}\"\n }\n\n values = {\n \"a\": \"sure\"\n }\n\n list(yaes.each(block, values))\n # [\n # ({\"ya\": \"{{ a }}\"}, {\"a\": \"sure\"})\n # ]\n\nThe behavior is the same if you send a list of blocks::\n\n list(yaes.each([block], values))\n # [\n # ({\"ya\": \"{{ a }}\"}, {\"a\": \"sure\"})\n # ]\n\nrequires\n--------\n\nIf a requires keyword is present, all the keys listed must be in values for the block to emitted::\n\n blocks = [\n {\n \"name\": \"one\",\n \"requires\": \"a\"\n },\n {\n \"name\": \"twp\",\n \"requires\": [\"a\", \"b\"]\n }\n ]\n\n values = {\n \"a\": \"sure\"\n }\n\n list(yaes.each(blocks, values))\n # [\n # ({\"name\": \"one\"}, {\"a\": \"sure\"})\n # ]\n\n.. note::\n\n requires can be a str or list of str.\n\nThis is useful for modules like opengui, where we don't want to evaluate the conditions on some fields\nunless other fields in those conditions actually have values.\n\ntranspose\n---------\n\nIf a transpose keyword is present, it'll use the key pairs to transpose the values::\n\n blocks = [\n {\n \"name\": \"one\",\n \"transpose\": {\n \"b\": \"a\"\n }\n }\n ]\n\n values = {\n \"a\": \"sure\"\n }\n\n list(yaes.each(blocks, values))\n # [\n # ({\"name\": \"one\"}, {\"a\": \"sure\", \"b\": \"sure\"})\n # ]\n\n.. note::\n\n you can have multiple values to transpose\n\nThis is useful if you're re-using a template that uses veriables and you want to replace\nthem with your usage's specific variables.\n\niterate\n-------\n\nIf a iterate keyword is present, it'll use the key pairs to iterate new values::\n\n blocks = [\n {\n \"name\": \"{{ fruit }}\",\n \"iterate\": {\n \"fruit\": \"fruits\"\n }\n }\n ]\n\n values = {\n \"fruits\": [\n \"apple\",\n \"pear\",\n \"orange\"\n ]\n }\n\n list(yaes.each(blocks, values))\n # [\n # (\n # {\n # \"name\": \"{{ fruit }}\"\n # },\n # {\n # \"fruit\": \"apple\",\n # \"fruits\": [\n # \"apple\",\n # \"pear\",\n # \"orange\"\n # ]\n # }\n # ),\n # (\n # {\n # \"name\": \"{{ fruit }}\"\n # },\n # {\n # \"fruit\": \"pear\",\n # \"fruits\": [\n # \"apple\",\n # \"pear\",\n # \"orange\"\n # ]\n # }\n # ),\n # (\n # {\n # \"name\": \"{{ fruit }}\"\n # },\n # {\n # \"fruit\": \"orange\",\n # \"fruits\": [\n # \"apple\",\n # \"pear\",\n # \"orange\"\n # ]\n # }\n # )\n # ]\n\n.. note::\n\n you can have multiple values to iterate, and it'll iterate over the different\n pairs alphabetically by key\n\nThis is useful with opengui as you can take the values of a multi option field and\nuse those values to create a new field for each option selected.\n\ncondition\n---------\n\nIf a condition keyword is present, it'll only emit the block if the condition evaluates True::\n\n blocks = [\n {\n \"name\": \"one\",\n \"condition\": \"{? a == 1 ?}\"\n },\n {\n \"name\": \"two\",\n \"condition\": \"{? a == 2 ?}\"\n }\n ]\n\n values = {\n \"a\": 1\n }\n\n list(yaes.each(blocks, values))\n # [\n # ({\"name\": \"one\"}, {\"a\": 1})\n # ]\n\n.. note::\n\n make sure you use '{?' and '?}' in the condition so it renders as a boolean.\n\nThis is useful if you only want to use a block under certain conditions.\n\nblocks\n------\n\nIf a blocks keyword is present, it'll expand those blocks, using the parent block as a base::\n\n blocks = [\n {\n \"base\": \"value\",\n \"blocks\": [\n {\n \"name\": \"one\"\n },\n {\n \"name\": \"two\",\n \"base\": \"override\"\n }\n ]\n }\n ]\n\n values = {\n \"a\": 1\n }\n\n list(yaes.each(blocks, values))\n # [\n # (\n # {\n # \"base\": \"value\",\n # \"name\": \"one\"\n # },\n # {\n # \"a\": 1\n # }\n # ),\n # (\n # {\n # \"base\": \"override\",\n # \"name\": \"two\"\n # },\n # {\n # \"a\": 1\n # }\n # )\n # ]\n\n.. note::\n\n blocks within blocks with control keywords will have those keywords evaluated\n\nThis is useful if you have a condition or iterate that you want to apply to multiple\nblock without having to use those keywords on each block.\n\nvalues\n------\n\nIf a values keyword is present, it'll merge those values into teh values emitted::\n\n blocks = [\n {\n \"name\": \"one\"\n },\n {\n \"name\": \"two\",\n \"values\": {\n \"a\": 2,\n \"c\": \"{{ b }}sah\"\n }\n }\n ]\n\n values = {\n \"a\": 1,\n \"b\": \"yes\"\n }\n\n list(yaes.each(blocks, values))\n # [\n # (\n # {\n # \"name\": \"one\"\n # },\n # {\n # \"a\": 1,\n # \"b\": \"yes\"\n # }\n # ),\n # (\n # {\n # \"name\": \"two\"\n # },\n # {\n # \"a\": 2,\n # \"b\": \"yes\",\n # \"c\": \"yessah\"\n # }\n # )\n # ]\n\n.. note::\n\n you can have multiple pairs in values\n\nThis is useful if you want to override the existing values but at this point I don't\nthink even I've ever used it.\n",
"bugtrack_url": null,
"license": null,
"summary": "Yet Another Expansion Syntax (pronounced 'Yasssss Kweeeeen')",
"version": "0.2.5",
"project_urls": {
"Download": "https://github.com/gaf3/yaes",
"Homepage": "https://yaes.readthedocs.io/en/0.2.5/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "62a0c80ed6ad2b0128f43d2d720cda0dbdba5677ccffa4b15a433856e0ce31ce",
"md5": "98a8709c56d6dc8ab4a7d29d88ba4864",
"sha256": "6fe41669eb198f733a73b59e8d615881feb23bcb46e427f27b34018d377d307f"
},
"downloads": -1,
"filename": "yaes-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "98a8709c56d6dc8ab4a7d29d88ba4864",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7723,
"upload_time": "2024-12-07T14:28:35",
"upload_time_iso_8601": "2024-12-07T14:28:35.886387Z",
"url": "https://files.pythonhosted.org/packages/62/a0/c80ed6ad2b0128f43d2d720cda0dbdba5677ccffa4b15a433856e0ce31ce/yaes-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d658f538190eb99a6954d1d88da967f20b548d29b95cd3ab284f957885d039b",
"md5": "68ddf007047c8ff28610974b14733077",
"sha256": "74855bffed08c4a018495f8041a0f77f5f9e29bde74f768e8f35a02a51d547b4"
},
"downloads": -1,
"filename": "yaes-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "68ddf007047c8ff28610974b14733077",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7895,
"upload_time": "2024-12-07T14:28:36",
"upload_time_iso_8601": "2024-12-07T14:28:36.743694Z",
"url": "https://files.pythonhosted.org/packages/1d/65/8f538190eb99a6954d1d88da967f20b548d29b95cd3ab284f957885d039b/yaes-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-07 14:28:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gaf3",
"github_project": "yaes",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Jinja2",
"specs": [
[
"==",
"3.1.2"
]
]
},
{
"name": "overscore",
"specs": [
[
"==",
"0.1.2"
]
]
},
{
"name": "MarkupSafe",
"specs": [
[
"==",
"2.1.5"
]
]
},
{
"name": "sphinxter",
"specs": [
[
"==",
"0.1.7"
]
]
},
{
"name": "ptvsd",
"specs": [
[
"==",
"4.3.2"
]
]
},
{
"name": "coverage",
"specs": [
[
"==",
"6.4.2"
]
]
},
{
"name": "pylint",
"specs": [
[
"==",
"2.14.5"
]
]
}
],
"lcname": "yaes"
}