From ca8811044760c1b6eb8e8df13d33979663b72cce Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 9 Nov 2019 22:08:01 +0100 Subject: [PATCH] doc: get rid of sphinxcontrib.contentui I want to modify that code too, so let's integrate it. --- docs/requirements.txt | 1 - docs/source/_ext/showfile.css | 28 ++++++++++++++++++++++ docs/source/_ext/showfile.js | 12 ++++++++++ docs/source/_ext/showfile.py | 44 +++++++++++++++++++++++++++++++++++ docs/source/conf.py | 1 - src/plugins/host_energy.cpp | 2 +- src/plugins/host_load.cpp | 2 +- 7 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 docs/source/_ext/showfile.css create mode 100644 docs/source/_ext/showfile.js diff --git a/docs/requirements.txt b/docs/requirements.txt index ecb036b906..4302bfe80f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,4 @@ breathe sphinx>=1.8.0 sphinx_rtd_theme sphinx_tabs -sphinxcontrib.contentui javasphinx diff --git a/docs/source/_ext/showfile.css b/docs/source/_ext/showfile.css new file mode 100644 index 0000000000..eb44eab909 --- /dev/null +++ b/docs/source/_ext/showfile.css @@ -0,0 +1,28 @@ + +/** + * + */ +.toggle-tab { + margin-bottom: 40px; +} + +.toggle-header { + display: block; + clear: both; + cursor: pointer; +} +.toggle-header p {display: inline; } +.toggle-header strong {color: #2980b9 } + +.toggle-header:after { + content: " ▼"; +} + +.toggle-header.open:after { + content: " ▲"; +} + +.toggle-content { + display: none; + margin-bottom: 20px; +} diff --git a/docs/source/_ext/showfile.js b/docs/source/_ext/showfile.js new file mode 100644 index 0000000000..7dae2b12f7 --- /dev/null +++ b/docs/source/_ext/showfile.js @@ -0,0 +1,12 @@ + +$(function() { + /** + * Toggle logic + */ + $('.toggle-content').hide() + $('.toggle-header').click(function () { + $(this).toggleClass("open"); + $(this).next('.toggle-content').toggle('400'); + }) +}); + diff --git a/docs/source/_ext/showfile.py b/docs/source/_ext/showfile.py index 39790a0cdd..5d79a32fdf 100644 --- a/docs/source/_ext/showfile.py +++ b/docs/source/_ext/showfile.py @@ -10,6 +10,9 @@ from docutils.statemachine import StringList from sphinx.util.osutil import copyfile from sphinx.util import logging +CSS_FILE = 'showfile.css' +JS_FILE = 'showfile.js' + class ShowFileDirective(Directive): """ Show a file or propose it to download. @@ -105,7 +108,48 @@ class ExampleTabDirective(Directive): self.state.nested_parse(self.content, self.content_offset, node) return node.children +class ToggleDirective(Directive): + has_content = True + option_spec = {'header': directives.unchanged} + optional_arguments = 1 + + def run(self): + node = nodes.container() + node['classes'].append('toggle-content') + + par = nodes.container() + par['classes'].append('toggle-header') + if self.arguments and self.arguments[0]: + par['classes'].append(self.arguments[0]) + + self.state.nested_parse(StringList([self.options["header"]]), self.content_offset, par) + self.state.nested_parse(self.content, self.content_offset, node) + + return [par, node] + +def add_assets(app): + app.add_stylesheet(CSS_FILE) + app.add_javascript(JS_FILE) + + +def copy_assets(app, exception): + if app.builder.name not in ['html', 'readthedocs'] or exception: + return + logger = logging.getLogger(__name__) + logger.info('Copying showfile stylesheet/javascript... ', nonl=True) + dest = os.path.join(app.builder.outdir, '_static', CSS_FILE) + source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) + copyfile(source, dest) + dest = os.path.join(app.builder.outdir, '_static', JS_FILE) + source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) + copyfile(source, dest) + logger.info('done') + def setup(app): + app.add_directive('toggle-header', ToggleDirective) app.add_directive('showfile', ShowFileDirective) app.add_directive('example-tab', ExampleTabDirective) + app.connect('builder-inited', add_assets) + app.connect('build-finished', copy_assets) + diff --git a/docs/source/conf.py b/docs/source/conf.py index fe63c21a97..1839d11d5c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -54,7 +54,6 @@ extensions = [ 'sphinx.ext.intersphinx', 'sphinx.ext.autosummary', 'sphinx_tabs.tabs', - 'sphinxcontrib.contentui', 'javasphinx', 'showfile', 'autodoxy', diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 5cbb75c2c0..45d75ed3db 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -18,7 +18,7 @@ SIMGRID_REGISTER_PLUGIN(host_energy, "Cpu energy consumption.", &sg_host_energy_ /** @defgroup plugin_host_energy - @rst + @beginrst This is the energy plugin, enabling to account not only for computation time, but also for the dissipated energy in the simulated platform. To activate this plugin, first call :cpp:func:`sg_host_energy_plugin_init()` before your :cpp:func:`MSG_init()`, and then use diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index 73debe7269..3885580d25 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -14,7 +14,7 @@ SIMGRID_REGISTER_PLUGIN(host_load, "Cpu load", &sg_host_load_plugin_init) /** @defgroup plugin_host_load - @rst + @beginrst Simple plugin that monitors the current load for each host. -- 2.20.1