Skip to content

Commit

Permalink
✨ add tags option for list2need directive (#1296)
Browse files Browse the repository at this point in the history
The `tags` option sets these tags on all generated needs

Co-authored-by: OFFICE\cs <[email protected]>
  • Loading branch information
christopheseyler and OFFICE\cs authored Oct 5, 2024
1 parent 3534131 commit 1e473e7
Show file tree
Hide file tree
Showing 6 changed files with 1,517 additions and 2 deletions.
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

0 comments on commit 1e473e7

Please sign in to comment.