Skip to content

Commit 75fd3c9

Browse files
authored
✨ Extend c.this_doc() to all directives with filter option (#1405)
extending #1393
1 parent 8ae2918 commit 75fd3c9

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

docs/directives/needextend.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ Default: false
9595
Extending needs in current page
9696
-------------------------------
9797

98-
.. versionadded:: 4.3.0
98+
.. versionadded:: 5.0.0
9999

100-
Additionally, to common :ref:`filter_string` variables, the ``c.this_doc()`` function is made available,
100+
The ``c.this_doc()`` function is made available,
101101
to filter for needs only in the same document as the ``needextend``.
102102

103-
You can use ``needextend``'s filter string to set default option values for a group of needs.
104-
105103
The following example would set the status of all needs in the current document,
106104
which do not have the status set explicitly, to ``open``.
107105

@@ -110,7 +108,7 @@ which do not have the status set explicitly, to ``open``.
110108
.. needextend:: c.this_doc() and status is None
111109
:status: open
112110

113-
See also: :ref:`needs_global_options` for setting a default option value for all needs.
111+
See also, :ref:`filter_current_page` and :ref:`needs_global_options` for setting a default option value for all needs.
114112

115113
Changing links
116114
--------------

docs/filter.rst

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,45 @@ If it is invalid or returns False, the related need is not taken into account fo
188188
.. needlist::
189189
:filter: "filter_example" in tags and (("B" in tags or ("spec" == type and "closed" == status)) or "test" == type)
190190

191+
.. _filter_current_page:
192+
193+
Filtering for needs on the current page
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
.. versionadded:: 5.0.0
197+
198+
Additionally, to common :ref:`filter_string` variables,
199+
the ``c.this_doc()`` function is for most directives,
200+
to filter for needs only in the same document as the directive.
201+
202+
.. need-example::
203+
204+
.. needtable::
205+
:filter: c.this_doc()
206+
:style: datatables
207+
208+
.. _re_search:
209+
210+
search
211+
~~~~~~
212+
213+
search(pattern, variable) is based on
214+
`Pythons re.search() function <https://docs.python.org/3/library/re.html#re.search>`_
215+
216+
The first parameter must be a regular expression pattern.
217+
The second parameter should be one of the above variables(status, id, content, ..)
218+
219+
.. dropdown:: Show example
220+
221+
This example uses a regular expressions to find all needs with an e-mail address in title.
222+
223+
.. need-example::
224+
225+
.. req:: Set admin e-mail to [email protected]
226+
227+
.. needlist::
228+
:filter: search("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", title)
229+
191230
.. _filter_string_performance:
192231

193232
Filter string performance
@@ -224,28 +263,6 @@ To debug which filters are being used across your project and their run times, y
224263
This is deprecated and will be removed in a future version.
225264
Instead use the above :ref:`needs_debug_filters` configuration option.
226265

227-
.. _re_search:
228-
229-
search
230-
~~~~~~
231-
232-
search(pattern, variable) is based on
233-
`Pythons re.search() function <https://docs.python.org/3/library/re.html#re.search>`_
234-
235-
The first parameter must be a regular expression pattern.
236-
The second parameter should be one of the above variables(status, id, content, ..)
237-
238-
.. dropdown:: Show example
239-
240-
This example uses a regular expressions to find all needs with an e-mail address in title.
241-
242-
.. need-example::
243-
244-
.. req:: Set admin e-mail to [email protected]
245-
246-
.. needlist::
247-
:filter: search("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", title)
248-
249266
.. _filter_code:
250267

251268
Filter code

sphinx_needs/filter_common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def process_filters(
180180
needs_config,
181181
filter_data["filter"],
182182
location=location,
183+
origin_docname=filter_data["docname"],
183184
)
184185
else:
185186
# The filter results may be dirty, as it may continue manipulated needs.
@@ -413,6 +414,7 @@ def filter_needs_view(
413414
location: tuple[str, int | None] | nodes.Node | None = None,
414415
append_warning: str = "",
415416
strict_eval: bool = False,
417+
origin_docname: str | None = None,
416418
) -> list[NeedsInfoType]:
417419
if not filter_string:
418420
return list(needs.values())
@@ -440,6 +442,7 @@ def filter_needs_view(
440442
current_need,
441443
location=location,
442444
append_warning=append_warning,
445+
origin_docname=origin_docname,
443446
)
444447

445448

@@ -452,6 +455,7 @@ def filter_needs_parts(
452455
location: tuple[str, int | None] | nodes.Node | None = None,
453456
append_warning: str = "",
454457
strict_eval: bool = False,
458+
origin_docname: str | None = None,
455459
) -> list[NeedsInfoType]:
456460
if not filter_string:
457461
return list(needs)
@@ -479,6 +483,7 @@ def filter_needs_parts(
479483
current_need,
480484
location=location,
481485
append_warning=append_warning,
486+
origin_docname=origin_docname,
482487
)
483488

484489

0 commit comments

Comments
 (0)