Skip to content

Commit

Permalink
Adds "needs_table_classe" config option
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
danwos committed Aug 24, 2021
1 parent ed5c074 commit 852350b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Expand Up @@ -18,6 +18,10 @@ License
(`#344 <https://github.com/useblocks/sphinxcontrib-needs/issues/344>`_)
* Improvement: Providing :ref:`needs_warnings_always_warn` to raise sphinx-warnings for each not passed :ref:`needs_warnings`.
(`#344 <https://github.com/useblocks/sphinxcontrib-needs/issues/344>`_)
* Improvement: Providing :ref:`needs_table_classes` to allow to set custom table css classes, to better support
themes like ReadTheDocs.
(`#305 <https://github.com/useblocks/sphinxcontrib-needs/issues/305>`_)


0.7.1
-----
Expand Down
21 changes: 18 additions & 3 deletions docs/configuration.rst
Expand Up @@ -993,7 +993,7 @@ Due to the nature of sphinx logging, a sphinx-warning may be printed wherever in
needs_warnings_always_warn
~~~~~~~~~~~~~~~~~~~~~~~~~~
This option if set to ``True``, will allow to log not passed :ref:`needs_warnings` into a given file if using your sphinx build
This option if set to ``True``, will allow to log not passed :ref:`needs_warnings` into a given file if using your sphinx build
command with ``-w``.
Default: ``False``.
Expand All @@ -1004,10 +1004,10 @@ For example, set this option to True:
needs_warnings_always_warn = True
Using sphinx build command ``sphinx-build -M html {srcdir} {outdir} -w error.log``, all the not passed :ref:`needs_warnings` will be
Using sphinx build command ``sphinx-build -M html {srcdir} {outdir} -w error.log``, all the not passed :ref:`needs_warnings` will be
logged into file error.log as you specified.
If use ``sphinx-build -M html {srcdir} {outdir} -W -w error.log``, the first not passed :ref:`needs_warnings` will stop the build and
If use ``sphinx-build -M html {srcdir} {outdir} -W -w error.log``, the first not passed :ref:`needs_warnings` will stop the build and
be logged into the file error.log.
.. _needs_layouts:
Expand Down Expand Up @@ -1206,6 +1206,21 @@ keys:
The related css class definition must be done by the user, e.g. by :ref:`own_css`.
(*optional*) (*default*: ``external_link``)
.. _needs_table_classes:
needs_table_classes
~~~~~~~~~~~~~~~~~~~
.. versionadded:: 0.7.2
Allows to define custom CSS classes, which get set for the HTML tables of ``need`` and ``needtable``.
This may be needed to avoid custom table handling of some specific Sphinx theme like ReadTheDocs.
.. code-block:: rst
needs_table_classes = ['my_custom_class', 'another_class']
Default: ``['rtd-exclude-wy-table']``
Removed options
---------------
Expand Down
23 changes: 6 additions & 17 deletions sphinxcontrib/needs/css/common.css
Expand Up @@ -4,23 +4,6 @@ table.need td {
white-space: normal;
}

/* Needed for RTD theme.
Manipulates it for EVERY table, so also none sphinx-needs tables
Another solution would be to use JS, to address only divs, which have a sphinx-needs table as child.*/
div.wy-table-responsive {
overflow: unset;
margin-bottom: unset;
}
/* Bringing Head and content columns align*/
/*solution from https://datatables.net/forums/discussion/comment/72586/#Comment_72586*/
/*table.dataTable,*/
/*table.dataTable thead th,*/
/*table.dataTable tbody td {*/
/* -webkit-box-sizing: content-box;*/
/* -moz-box-sizing: content-box;*/
/* box-sizing: content-box;*/
/*}*/

table.NEEDS_TABLE {
display: block;
overflow-x: auto;
Expand All @@ -44,6 +27,12 @@ table.need tr.footer div.line-block {
margin-bottom: 0;
}

/* START CUSTOM ReadTheDocs theming css START */
div.dataTables_scrollHeadInner > table.rtd-exclude-wy-table {
margin-bottom: 0px;
}
/* END CUSTOM ReadTheDocs theming css START */

.toggle .header {
display: block;
clear: both;
Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/needs/directives/needtable.py
Expand Up @@ -135,6 +135,8 @@ def process_needtables(app, doctree, fromdocname):

# Prepare table
classes = ["NEEDS_{style}".format(style=style)]
classes.extend(app.config.needs_table_classes)

content = nodes.table(classes=classes)
tgroup = nodes.tgroup()

Expand Down
5 changes: 4 additions & 1 deletion sphinxcontrib/needs/layout.py
Expand Up @@ -155,7 +155,10 @@ def __init__(self, app, need, layout, node, style=None, fromdocname=None):
else:
self.fromdocname = fromdocname

classes = ["need", "needs_grid_" + self.layout["grid"], "needs_layout_" + self.layout_name]
# For ReadTheDocs Theme we need to add 'rtd-exclude-wy-table'.
classes = ["need", "needs_grid_" + self.layout["grid"],
"needs_layout_" + self.layout_name]
classes.extend(app.config.needs_table_classes)

self.style = style or self.need["style"] or getattr(self.app.config, "needs_default_style", None)

Expand Down
3 changes: 3 additions & 0 deletions sphinxcontrib/needs/needs.py
Expand Up @@ -206,6 +206,9 @@ def setup(app):

app.add_config_value("needs_external_needs", [], "html")

# Additional classes to set for needs and needtable.
app.add_config_value("needs_table_classes", ['rtd-exclude-wy-table'], "html", types=[list])

# Define nodes
app.add_node(Need, html=(html_visit, html_depart), latex=(latex_visit, latex_depart))
app.add_node(
Expand Down

0 comments on commit 852350b

Please sign in to comment.