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

PR - Add 'hide' support and a new meta-data option to List2need directive #1345

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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", "")
christopheseyler marked this conversation as resolved.
Show resolved Hide resolved
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