[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
X-original-commit: 269173caac
Part-of: odoo/documentation#1692
This commit is contained in:
parent
31df0a841a
commit
990ca4f7ca
3
conf.py
3
conf.py
@ -121,9 +121,6 @@ extensions = [
|
||||
# Redirection generator
|
||||
'redirects',
|
||||
|
||||
# Code switcher (switcher and case directives)
|
||||
'switcher',
|
||||
|
||||
# Content tabs
|
||||
'sphinx_tabs.tabs',
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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]
|
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user