diff --git a/Makefile b/Makefile
index aa8def898..c0f780b3a 100644
--- a/Makefile
+++ b/Makefile
@@ -30,13 +30,16 @@ clean:
$(RM_CMD) extensions/odoo_theme/static/style.css
@echo "Cleaning finished."
-edi: SPHINXOPTS += -A collapse_menu=True
+#edi: SPHINXOPTS += -A collapse_menu=True # If needed, comment rather than setting False
edi: VERSIONS += 12.0,13.0,14.0
edi: CANONICAL_VERSION += 14.0
edi: LANGUAGES += en,fr,es
edi: CURRENT_LANG += fr
edi: clean html
+static: extensions/odoo_theme/static extensions/odoo_theme/static/style.css
+ cp -r extensions/odoo_theme/static/* _build/html/_static/
+
html: extensions/odoo_theme/static/style.css
@echo "Starting build..."
$(SPHINX_BUILD) -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(BUILD_DIR)/html
diff --git a/content/applications.rst b/content/applications.rst
index 5c5b86a92..8ea646be5 100644
--- a/content/applications.rst
+++ b/content/applications.rst
@@ -1,3 +1,5 @@
+:show_content:
+
============
Applications
============
diff --git a/content/contributing/documentation.rst b/content/contributing/documentation.rst
index a168b5e12..81b3bef70 100644
--- a/content/contributing/documentation.rst
+++ b/content/contributing/documentation.rst
@@ -1,5 +1,5 @@
-:empty_page:
+:show_content:
=================================
Contributing to the documentation
diff --git a/extensions/odoo_theme/__init__.py b/extensions/odoo_theme/__init__.py
index c9dc239b7..57639caa8 100644
--- a/extensions/odoo_theme/__init__.py
+++ b/extensions/odoo_theme/__init__.py
@@ -1,32 +1,27 @@
-from . import pygments_override
-from . import translator
-
-import sphinx.builders.html
+from docutils import nodes
from sphinx import addnodes
from sphinx.environment.adapters import toctree
-from docutils import nodes
+
+from . import pygments_override, translator
def setup(app):
app.set_translator('html', translator.BootstrapTranslator)
- # VFE TODO check if default meta initialization is necessary.
- # If not, remove update_meta method
- app.connect('html-page-context', update_meta)
+ app.connect('html-page-context', set_missing_meta)
+ app.add_js_file('js/utils.js') # Keep in first position
app.add_js_file('js/layout.js')
app.add_js_file('js/menu.js')
app.add_js_file('js/page_toc.js')
-def update_meta(app, pagename, templatename, context, doctree):
- meta = context.get('meta')
- if meta is None:
- meta = context['meta'] = {}
-
-# TODO VFE detailed explanation of the patch logic and use.
+def set_missing_meta(app, pagename, templatename, context, doctree):
+ if context.get('meta') is None: # Pages without title (used with `include::`) have no meta
+ context['meta'] = {}
class Monkey(object):
+ """ Replace patched method of an object by a new method receiving the old one in argument. """
def __init__(self, obj):
self.obj = obj
def __call__(self, fn):
@@ -36,41 +31,67 @@ class Monkey(object):
@Monkey(toctree.TocTree)
def resolve(old_resolve, tree, docname, *args, **kwargs):
+
+ def _update_toctree_nodes(_node) -> None:
+ """ Make necessary changes to Docutils' nodes of the toc.
+
+ Internal structure of toc nodes:
+
+ -
+
+
+
+
+
+ """
+ if isinstance(_node, nodes.reference): # The node is a reference ()
+ _node_docname = _get_docname(_node)
+ _clear_reference_if_empty_page(_node, _node_docname)
+ _set_docname_as_class(_node, _node_docname)
+ elif isinstance(_node, (addnodes.compact_paragraph, nodes.bullet_list, nodes.list_item)):
+ for _subnode in _node.children:
+ _update_toctree_nodes(_subnode)
+
+ def _get_docname(_node):
+ """
+ docname = a/b/c/the_page_being_rendered
+ _ref = ../../contributing/documentation
+ _path_parts = ['..', '..', 'contributing', 'documentation']
+ _res = ['a', 'contributing', 'documentation']
+ _docname = a/contributing/documentation
+ """
+ _ref = _node['refuri'].replace('.html', '')
+ _parent_directory_occurrences = _ref.count('..')
+ if not _parent_directory_occurrences: # The ref is already the docname
+ _docname = _ref
+ else:
+ _path_parts = _ref.split('/')
+ _res = docname.split('/')[:-(_parent_directory_occurrences+1)] \
+ + _path_parts[_parent_directory_occurrences:]
+ _docname = '/'.join(_res)
+ return _docname
+
+ def _clear_reference_if_empty_page(_reference_node, _node_docname):
+ """ Clear reference of 'empty' toctree pages.
+
+ Inspect parent node's siblings to determine whether the node references a toc and, if so,
+ clear its reference URL. ()
+ If the page has the `show_content` metadata, don't clear the reference.
+ """
+ if _node_docname and any(
+ isinstance(_subnode, nodes.bullet_list)
+ for _subnode in _reference_node.parent.parent.children
+ ): # The node references a toc
+ if 'show_content' not in tree.env.metadata[_node_docname]:
+ _reference_node['refuri'] = '#' # The page must not be accessible
+
+ def _set_docname_as_class(_reference_node, _node_docname):
+ _node_docname = _node_docname or docname # refuri==None <-> href="#"
+ _reference_node.parent.parent['classes'].append(f'o_menu_{_node_docname.replace("/", "_")}')
+
resolved_toc = old_resolve(tree, docname, *args, **kwargs)
- if resolved_toc:
- # Not sure set_class really does what we want.
- _toctree_add_empty_class(tree, resolved_toc, docname)
- resolved_toc['classes'].append('testtesttest')
+ if resolved_toc: # `resolve` returns None if the depth of the TOC to resolve is too high
+ _update_toctree_nodes(resolved_toc)
return resolved_toc
-
-def _toctree_add_empty_class(tree, node, docname) -> None:
- for subnode in node.children:
- if isinstance(subnode, (
- addnodes.compact_paragraph,
- nodes.list_item,
- nodes.bullet_list
- )):
- # for ,
- and
just recurse
- _toctree_add_empty_class(tree, subnode, docname)
- elif isinstance(subnode, nodes.reference):
- toc_ref = get_reference(subnode, docname)
- if toc_ref and 'empty_page' in tree.env.metadata[toc_ref]:
- subnode['classes'].append('o_empty_page')
-
-def get_reference(node, docname):
- ref = node['refuri'].replace('.html', '') # applications.html
- if ref.find('..') < 0:
- # direct reference
- return ref
- splitted_refuri = ref.split('/')
- count = 0 # Number of ../ in refuri
- for split in splitted_refuri:
- if split == "..":
- count += 1
- # ref = ../../../contributing/documentation
- # docname = services/legal/terms/enterprise
- # res = contributing/documentation
- res = docname.split('/')[:-(count+1)] + splitted_refuri[count:]
- return "/".join(
- res
- )
diff --git a/extensions/odoo_theme/layout.html b/extensions/odoo_theme/layout.html
index 4769cc960..a204bc5a3 100644
--- a/extensions/odoo_theme/layout.html
+++ b/extensions/odoo_theme/layout.html
@@ -64,11 +64,11 @@
{% set main_classes = [] %}
{% if pagename == master_doc %} {# The current page is the homepage #}
- {% set main_classes = main_classes + ['index'] %}
+ {% set main_classes = main_classes + ['index'] %} {# TODO ANVFE should be 'o_index' #}
{% endif %}
{% if 'code-column' in meta %} {# The page contains a 'memento' (side dynamic block) #}
- {% set main_classes = main_classes + ['has_code_col'] %}
+ {% set main_classes = main_classes + ['has_code_col'] %} {# TODO ANVFE see #}
{% endif %}
{% if 'classes' in meta %} {# The page source defines custom classes #}
diff --git a/extensions/odoo_theme/layout_templates/header.html b/extensions/odoo_theme/layout_templates/header.html
index a43d51d08..53c0884cf 100644
--- a/extensions/odoo_theme/layout_templates/header.html
+++ b/extensions/odoo_theme/layout_templates/header.html
@@ -1,6 +1,5 @@