[REM] extensions: remove the 'switcher' extension

The 'sphinx-tabs' extension is better in every aspect:
- Synchronize selected tabs (group tabs feature).
- No need for extra `code-block` directive (code tabs feature).
- Better looking.
- No custom Python, JS, or CSS.

task-2787415

Part-of: odoo/documentation#1688
This commit is contained in:
Antoine Vandevenne (anv) 2022-03-08 13:06:34 +00:00
parent 1e24b482b6
commit 269173caac
4 changed files with 0 additions and 123 deletions

View File

@ -117,9 +117,6 @@ extensions = [
# Redirection generator
'redirects',
# Code switcher (switcher and case directives)
'switcher',
# Content tabs
'sphinx_tabs.tabs',

View File

@ -512,25 +512,6 @@ header.o_main_header {
max-width: 100%;
}
.content-switcher {
.nav-tabs .nav-link.active {
background-color: #f8f8f8;
border-color: #dee2e6 #dee2e6 #f8f8f8;
font-weight: $fw_semibold;
}
.tab-content {
background: $doc_code-bg;
border: 1px $gray-300 solid;
border-top: 0;
div[class^="highlight"] {
border: 0;
margin: 0;
}
}
}
@include media-breakpoint-up(xl) {
width: 100%;
padding-right: 0;

View File

@ -1,65 +0,0 @@
import os.path
from docutils import nodes
from docutils.parsers.rst import Directive
from pygments.lexers import get_lexer_by_name
def setup(app):
app.add_directive('switcher', SwitcherDirective)
app.add_directive('case', CaseDirective)
app.connect('env-updated', add_statics)
return {
'parallel_read_safe': True,
'parallel_write_safe': True
}
def add_statics(app, env):
app.add_js_file('js/switcher.js')
env.config.html_static_path.append(statics())
statics = lambda *p: os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static', *p)
class SwitcherDirective(Directive):
has_content = True
def run(self):
self.assert_has_content()
body = nodes.compound('\n'.join(self.content), classes=['tab-content'])
self.state.nested_parse(self.content, self.content_offset, body)
titles = []
for child in body.children:
if isinstance(child, nodes.literal_block):
titles.append(get_lexer_by_name(child['language']).name)
else:
assert child['names'], (
"A switcher case must be either a code block or a compound with a name"
)
titles.append(' '.join(child['names']))
tabs = nodes.bullet_list('', *[
nodes.list_item('', nodes.Text(title), classes=['nav-link'])
for title in titles
], classes=['nav nav-tabs'] )
node = nodes.compound('', tabs, body, classes=['content-switcher'])
return [node]
class CaseDirective(Directive):
required_arguments = 1
final_argument_whitespace = True
has_content = True
def run(self):
self.assert_has_content()
node = nodes.compound('\n'.join(self.content), names=[self.arguments[0]])
self.state.nested_parse(self.content, self.content_offset, node)
return [node]

View File

@ -1,36 +0,0 @@
(function ($) {
// TODO EDI custom css for content-switcher logic
// can be placed as css inside the extension ideally
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.content-switcher').forEach(switcher => {
const links = switcher.querySelectorAll('ul li');
const linksArray = Array.from(links);
const tabs = switcher.querySelectorAll('.tab-content > div');
tabs.forEach(tab => {
tab.classList.add('tab-pane');
});
function select(index) {
links.forEach(link => {
link.classList.remove('active');
});
tabs.forEach(tab => {
tab.classList.remove('active');
});
links[index].classList.add('active');
tabs[index].classList.add('active');
}
select(0);
links.forEach(link => {
link.addEventListener('click', ev => {
// const clickedLink = ev.target.closest('ul li');
select(linksArray.indexOf(link));
});
});
});
});
})();