From 119b964b166b38791bbc063f8f6ecceb829aab2e Mon Sep 17 00:00:00 2001 From: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> Date: Wed, 13 Aug 2025 23:19:06 -0700 Subject: [PATCH] macros: change nested template key syntax, add docs --- docs/macros.md | 30 ++++++++++++++++++++++++++++-- src/tagstudio/core/macro_parser.py | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/macros.md b/docs/macros.md index 106e8cfb..0573cd28 100644 --- a/docs/macros.md +++ b/docs/macros.md @@ -73,7 +73,7 @@ If you're importing from an object or table-like source (i.e. JSON), you'll need Inside the new table we can now declare additional information about the native data formats and how they should be imported into TagStudio. -### Data Sources +### Action Configuration #### Key @@ -413,7 +413,7 @@ video = ["Animation (2D)", "Animated (Meta Tags)"] #### Many to 1 (Inverse Map) -By mapping a key of the name of one of your TagStudio tags to a list of source tags, you can declare a combination of required source tags that result in a wholly new matched TagStudio tag. This is useful if you use a single tag in your TagStudio library that is represented by multiple split tags from your source. +By mapping a key with the name of one of your TagStudio tags to a list of source tags, you can declare a combination of required source tags that result in a wholly new matched TagStudio tag. This is useful if you use a single tag in your TagStudio library that is represented by multiple separate tags from your source. ```toml [newgrounds.tags.inverse_map] @@ -421,3 +421,29 @@ By mapping a key of the name of one of your TagStudio tags to a list of source t "Animation (2D)" = ["drawing", "video"] "Animation (3D)" = ["3D", "video"] ``` + +### Templates + +Templates are part of the `input_data` action and allow you to take data from one or more keys of a source and combine them into a single value. Template sub-action tables must begin with the action name and end with `.template` (e.g. `[action.template]`). Source object keys can be embedded in a string value if surrounded by curly braces (`{}`). Nested keys are accessed by separating the keys with a dot (e.g. `{key.nested_key}`). + + +=== "Composite Template" + ```toml + [bluesky.template] + template = "https://www.bsky.app/profile/{author.handle}/post/{post_id}" + ts_type = "text_line" + name = "Source" + ``` +=== "Multiple Templates per Action" + ```toml + [[artstation.template]] + template = "Original Tags: {tags}" + ts_type = "text_box" + name = "Notes" + + [[artstation.template]] + template = "Original Mediums: {mediums}" + ts_type = "text_box" + name = "Notes" + ``` + diff --git a/src/tagstudio/core/macro_parser.py b/src/tagstudio/core/macro_parser.py index 18437b1b..e8824eef 100644 --- a/src/tagstudio/core/macro_parser.py +++ b/src/tagstudio/core/macro_parser.py @@ -452,7 +452,7 @@ def _fill_template( Args: template (str): The string containing placeholder keys. Key names should be surrounded in curly braces. (e.g. "{key}"). - Nested keys should be accessed with square bracket syntax. (e.g. "{key[nested_key]}"). + Nested keys are accessed by separating the keys with a dot (e.g. "{key.nested_key}"). table (dict[str, Any]): The table to lookup values from. table_key (str): The key to search for in the template and access the table with. template_key (str): Similar to table_key, but is not used for accessing the table and @@ -464,7 +464,7 @@ def _fill_template( if isinstance(value, dict): for v in value: - normalized_key: str = f"{key}[{str(v)}]" + normalized_key: str = f"{key}.{str(v)}" template = _fill_template(template, value, str(v), normalized_key) value = str(value)