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

✨ add tags option for list2need directive #1296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/directives/list2need.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ The amount of given link-types must be the amount of used levels minus 1.
* (NEED-D)Recalculate hash and compare


tags
~~~~

``tags`` sets tags globally to all items in the list.

.. code-block:: rst

.. list2need::
:types: req, spec
:tags: A, B

* (NEED-A)Login user
* (NEED-B)Provide login screen
* (NEED-C)Create password hash
* (NEED-D)Recalculate hash and compare


The tags ``A`` and ``B`` are attached to all ``NEED-A``, ``NEED-B``, ``NEED-C`` and ``NEED-D``.


List examples
-------------

Expand Down
15 changes: 15 additions & 0 deletions sphinx_needs/directives/list2need.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def presentation(argument: str) -> Any:
"delimiter": directives.unchanged,
"presentation": directives.unchanged,
"links-down": directives.unchanged,
"tags": directives.unchanged,
}

def run(self) -> Sequence[nodes.Node]:
Expand Down Expand Up @@ -106,6 +107,10 @@ def run(self) -> Sequence[nodes.Node]:
f"Unknown link configured: {down_link_raw}. "
f"Allowed are {', '.join(link_types)}"
)

# Retrieve tags defined at list level
tags = self.options.get("tags", "")

list_needs = []
# Storing the data in a sorted list
for content_line in content_raw.split("\n"):
Expand Down Expand Up @@ -190,6 +195,16 @@ def run(self) -> Sequence[nodes.Node]:
list_need["title"] = OPTION_AREA_REGEX.sub("", list_need["title"])
list_need["content"] = OPTION_AREA_REGEX.sub("", list_need["content"])

# Add tags defined at list level (if exists) to the ones potentially defined in the content
if tags:
if "options" not in list_need:
list_need["options"] = {}
current_tags = list_need["options"].get("tags", "")
if current_tags:
list_need["options"]["tags"] = current_tags + "," + tags
else:
list_need["options"]["tags"] = tags

template = Template(NEED_TEMPLATE, autoescape=True)

data = list_need
Expand Down
Loading