Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
56 changes: 56 additions & 0 deletions docs/directives/list2need.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,62 @@ tags
The tags ``A`` and ``B`` are attached to all ``NEED-A``, ``NEED-B``, ``NEED-C`` and ``NEED-D``.



hide
~~~~

``hide`` sets the hide-option globally to all items in the list.

.. code-block:: rst

.. list2need::
:types: req
:tags: A
:hide: True

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

All ``NEED-A``, ``NEED-B``, ``NEED-C`` and ``NEED-D`` requirements will be marked as hidden. This allows to easily create a list of requirements and presenting them as a table in the final output.

.. code-block:: rst

.. list2need::
:types: req
:tags: A
:hide: True

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

.. needtable::
:types: req
:tags: A
:style: table
:columns: id, title, content, links


meta-data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename meta-data to something with global or option in the name because we already have needs_global_options as a config parameter, which does something similar: setting values globally for specific needs.
That's the same here.

So, what about naming the parameter just global?`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to stay in the same mind, I've renamed to list_global_options

~~~~~~~~~

Meta-data can be set directly in the related line via, for example: ``((status="open"))``. This meta-data option allows to define meta-data that will be affected to all needs in the list, including extra custom options.

.. code-block:: rst

.. list2need::
:types: req
:tags: A
:meta-data: validation="Test, Review of Design", status="open"

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

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

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

def run(self) -> Sequence[nodes.Node]:
Expand Down Expand Up @@ -110,6 +112,8 @@ def run(self) -> Sequence[nodes.Node]:

# Retrieve tags defined at list level
tags = self.options.get("tags", "")
hide = self.options.get("hide", "")
metadata = self.options.get("meta-data", "")

list_needs = []
# Storing the data in a sorted list
Expand Down Expand Up @@ -205,6 +209,27 @@ def run(self) -> Sequence[nodes.Node]:
else:
list_need["options"]["tags"] = tags

if hide:
if "options" not in list_need:
list_need["options"] = {}
hide_option = list_need["options"].get("hide", "")
list_need["options"]["hide"] = hide_option

if metadata:
if "options" not in list_need:
list_need["options"] = {}
metadata_items = re.findall(r'([^=,]+)=["\']([^"\']+)["\']', metadata)

for key, value in metadata_items:
current_options = list_need["options"].get(key.strip(), "")

if current_options:
list_need["options"][key.strip()] = (
current_options + "," + value
)
else:
list_need["options"][key.strip()] = value

template = Template(NEED_TEMPLATE, autoescape=True)

data = list_need
Expand Down